etrader Posted March 13, 2011 Share Posted March 13, 2011 I have a set of strings come from an array with this structure New-Name.jpg | http://domain.com/original-name.jpg How I can download the images from the links to my local machine and rename them (to New-Name.jpg)? Quote Link to comment https://forums.phpfreaks.com/topic/230545-download-and-rename-images/ Share on other sites More sharing options...
sasa Posted March 14, 2011 Share Posted March 14, 2011 try <?php $test = 'slika.jpg | http://preview.filesonic.com/img/350541.jpg'; $test = explode('|', $test); $dest = trim($test[0]); $sorc = trim($test[1]); copy ($sorc, $dest); ?> Quote Link to comment https://forums.phpfreaks.com/topic/230545-download-and-rename-images/#findComment-1187237 Share on other sites More sharing options...
etrader Posted March 14, 2011 Author Share Posted March 14, 2011 wow! works perfectly ... THANKS Quote Link to comment https://forums.phpfreaks.com/topic/230545-download-and-rename-images/#findComment-1187315 Share on other sites More sharing options...
etrader Posted March 14, 2011 Author Share Posted March 14, 2011 This solution is perfect, but is it possible to get the file extension from the downloaded file? Now we get the extension from the $test string, but if downloading from e.g. file sharing websites, the url may not include the file name. And additionally, if the rar or zip file contains part1 part2, it will be considered as a part of the file name. I think if first downloading the file on the server, we can get the file information, then renaming. I have explored some codes, but none of them are comparable with your elegantly short idea; this is the reason that I continue this thread. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/230545-download-and-rename-images/#findComment-1187502 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.