Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
01-29-2007, 07:01 AM #1
how to rename images and save them to different folder using PHP?
( since this is an entirely different question i am posting it as a new message.)
i have an image here: htp://domain.com/images1/image.jpg
i would like to rename this image as renamedimage.jpg
and move it to another folder htp://domain.com/images2/renamedimage.jpg
how can this be done using PHP?
( i have thousands of images. so i am thinking of using some php script to do this task )
please reply with possible solutions.
thank you very much
01-29-2007, 08:11 AM #2
- Join Date
- Jul 2005
- Thanked 0 Times in 0 Posts
01-29-2007, 11:43 AM #3
thanks for the tip.
but i have a problem.
i used the code as follows:
i kept it in a while loop because there are thousands of images to rename
$file = 'htp://domain.com/images/image1.jpg';
$newfile = 'htp://domain.com/renamedimages/renamedimage1.jpg';
and the result is all the images are the same. ( image1 is copied into image2, image3, image4 and all )
i think i have to use imagedestroy function. but dont know how to use the function in this context.
i have tried several ways and the result is:
imagedestroy(): supplied argument is not a valid Image resource.
i could copy individual files very well using this function.
please inform me how to copy the images recursively.
thank you very much for any help
Last edited by student; 01-29-2007 at 03:08 PM. Reason: it didnt worked
01-30-2007, 06:51 PM #4
- Join Date
- Oct 2006
- Denver, Colorado USA
- Thanked 305 Times in 297 Posts
If the same source file given by the $file variable got copied into each destination $newfile, that would indicate that the $file variable did not get modified within your while loop for each file.
imagedestroy() is an GD image manipulation function and not a file handling function - http://www.php.net/manual/en/ref.filesystem.php If you want to delete a file after it has been successfully copied, use the unlink() function - http://www.php.net/unlink
If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.