coderama coderama - 19 days ago 9
PHP Question

PHP Copy command failing when spaces?

I am executing the following commands:

<?php
copy ("http://localhost/.../DSCF8253.JPG" , "sites/default/files/DSCF8253.JPG"); // Success!
copy ("http://localhost/.../DSCF8260.JPG" , "sites/default/files/DSCF8260.JPG"); // Success!
copy ("http://localhost/.../HERMAN 085.jpg" , "sites/default/files/HERMAN 085.jpg" ); // Fail!
?>


The first two copy fine, but not the last one. Why?

It must have something to do with the filenames (the last one has a SPACE before the 085).

Any help would be greatly appreciated!

Answer
http://localhost/.../HERMAN 085.jpg

Should be

http://localhost/.../HERMAN%20085.jpg

Copy & the http wrappers are less forgiving then browsers / user-agents when it comes to invalid urls. A space in an url is invalid, so it should be urlencode'd.