Reputation: 22030
I am trying to copy an image from https://i.sstatic.net/KkoAp.jpg to localhost. It gives me a
Warning:
copy(https://i.sstatic.net/KkoAp.jpg)
[function.copy]: failed to open stream: Permission denied in/var/www/html/test/timg
The folder timg
has got 777 access
copy("https://i.sstatic.net/KkoAp.jpg","timg/avcsLXI.jpg");
move_uploaded_file()
throws the same error
I have seen various examples but not seen one with copy. I do not want to use fopen or curl for this purpose.
Upvotes: 1
Views: 9159
Reputation: 1958
If your looking for an alternative other than fopen or curl, you could use wget:
shell_exec('wget -P timg/avcsLXI.jpg http://i.imgur.com/avcsLXI.jpg');
Upvotes: 0
Reputation: 360672
If timg
is a folder, then there's your problem. copy()
works on FILES for both the source AND destination. YOu can't have just a folder for the destination,b ecause copy will try to replace the folder with the file you're copying from. So
copy("http://i.imgur.com/avcsLXI.jpg","timg"); // folder only, WRONG
copy("http://i.imgur.com/avcsLXI.jpg","timg/thepic.jpg"); // correct, folder+file
Upvotes: 1
Reputation: 28911
You need to specify the desitination filename, not just the directory.
This works for me:
copy("http://i.imgur.com/avcsLXI.jpg","timg/avcsLXI.jpg");
Note that some webhosts don't allow URLs as the source path for security reasons, this will only work if "fopen wrappers" have been enabled.
Upvotes: 3