1

im copying a file from another domain. It does not give me any errors but the files does not get recognized and its different size from the original file. Its the same extension i checked. so im kinda clueless.

if (!copy('http://maholi.com/image/data/Products/Linen - Juvenile and Infant/1440.jpg', $_SERVER['DOCUMENT_ROOT'].'/resources/categories/tttt6.jpg')) {
echo "failed";
}

any ideas?

Andrew
  • 73
  • 2
  • 8
  • 1
    Most likely you did not really copy the file but receive some html error message or similar form the remote system. PHP cannot known what you expect inside the file, so it stored whatever it receives. I suggest you simply take a look into the file to see what it contains. – arkascha Nov 05 '15 at 20:05
  • Did you try opening it in a text editor? Some sites might serve html instead of the image if they don't like your referer. – developerwjk Nov 05 '15 at 20:06
  • ^^ make sure you use a text editor to open the file –  Nov 05 '15 at 20:06
  • http://php.net/manual/en/function.error-reporting.php – Funk Forty Niner Nov 05 '15 at 20:06
  • How about removing spaces from src file "`http://maholi.com/image/data/Products/Linen%20-%20Juvenile%20and%20Infant/1440.jpg`" and make sure the dest path exists. – Hasse Björk Nov 05 '15 at 20:08
  • yes you guys are right. i opened with text editor and it shows a full html page for some reason.ill try encoding the src now – Andrew Nov 05 '15 at 20:12
  • yes i updated the spacing and it did the job! thank you! – Andrew Nov 05 '15 at 20:16
  • is there a php function that would do this for me? cause i got an array of those src's – Andrew Nov 05 '15 at 20:16
  • of course you have permission to use those images ;) ..`urlencode()` –  Nov 05 '15 at 20:18
  • i tried that and it gives out an error since it converts the whole string , not just spaces. – Andrew Nov 05 '15 at 20:31

1 Answers1

0

This works fine for me:

if (!copy('http://maholi.com/image/data/Products/Linen%20-%20Juvenile%20and%20Infant/1440.jpg', $_SERVER['DOCUMENT_ROOT'].'/tttt6.jpg')) {
  echo "failed";
}

Edit: URL's are not allowed to contain spaces. See "Is a URL allowed to contain a space?". Your web browser will automatically encode illegal characters, making you believe they are allowed.

Community
  • 1
  • 1
Hasse Björk
  • 1,431
  • 13
  • 19