Re: using PHP script to add address'es of all picture files in a dir to MYSQL DB

From: Date: Wed, 07 Nov 2001 10:49:44 +0000
Subject: Re: using PHP script to add address'es of all picture files in a dir to MYSQL DB
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-73716@lists.php.net to get a copy of this message
If you are in an unix shell, you can use the find ./ -name '*.jpg' and pipe it to awk '{ print "mysql -e 'insert into table (path_to_pict) values ('" $0 "')" }' > execute.sh Chown u+x the execute.sh and run it. I don't have the proper awk syntax because of the ' and " but if you figure it out, it should be pretty simple. Robin Daniel wrote: > > Hi, > > I want to make a simple database driven photo gallery for my site where > users can search the picture descriptions to find the pictures they want, > all fairly simple PHP/MySQL stuff which I know. My big problem is that I > have like 500+ images I want to put into the MySQL DB and I am way too lazy > to consider doing it the hard way. I was wondering if it would be possible > to write a PHP script which would get a list of all the .jpg files in its > current directory and then insert a reference for each file (basically just > its location on the web server) into the MySQL PHOTO table? I was thinking > about this on the train yesterday so heres the pseudo PHP/C code of the sort > of script I was thinking about(I don't know the PHP file functions): > > //get the number of jpeg files in same dir as this script (I don't know code > for this) > $NumFiles = GetNumberOfJPGFilesInDirectory(); > While ($NumFiles > 0) > { > //get file location of current jpeg file (I don't know code for this) > $FileName = GetFileNameAndLocation($NumFiles); > // construct MySQL query > $sql = "INSERT INTO PHOTO SET " . "FILE='$FileName "; > //add file location of current jpeg and do error handling (easy stuff) > if (mysql_query($sql)) > { > echo("Photo " . $FileName ." has been added.<br>"); > }else > { > echo("Error adding photo: " . mysql_error() . " <br>"); > } > $NumFiles = $NumFiles-1; > } > > Would anyone be able to help me get the code for this script right? I can > do basic PHP & MySQL stuff but I am not familiar with PHP file functions so > I need someone to help me get it working... > > Cheers, > > Daniel > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > For additional commands, e-mail: php-general-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net

« previous php.general (#73716) next »