M
M
Max Payne2015-01-21 16:46:54
PHP
Max Payne, 2015-01-21 16:46:54

Why is the php copy image not saved?

$url = "http://img1.goodfon.ru/original/1920x1200/3/26/zmeya-udav-kolca.jpg";
copy($url,'tmpimg.jpg');
file_put_contents('tmpimg.jpg',$url);

File not saved :(

Answer the question

In order to leave comments, you need to log in

3 answer(s)
D
Dmitry, 2015-01-21
@YardalGedal

file_put_contents as the second argument does not require the URL/PATH of the file, but the content. Those. it would be right

file_put_contents('tmpimg.jpg', file_get_contents($url));

S
SagePtr, 2015-01-21
@SagePtr

Because you first copy this picture, and then overwrite this file with the file_put_contents command, writing the picture url inside. Remove file_put_contents altogether, it's not needed here.
Well, it would not hurt to turn on error output: phpfaq.ru/debug

E
Eugene, 2015-01-21
@Nc_Soft

So what about nginx?
This is enough to save the image
$url = " img1.goodfon.ru/original/1920x1200/3/26/zmeya-udav... ";
copy($url,'tmpimg.jpg');

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question