0

How to save the image from browser into Directory by PHP code..

First I pass an image into a php file via:

<http://localhost/filename.php?image=image.png>

I have code like below in filename.php:

$image = $_GET['image'];
header('Content-type: image/png');
imagepng($image);

now the image will be shown in the browser. but how I save it into directory? I tried this

 file_put_contents(DIR_IMAGE.'watermark.png', file_get_contents(the link http://.....=image.png));

the files is saving into the directory but the file is corrupted/damage. how can I do workable? Thanks

4

1 回答 1

0

您可以使用fopen打开目录和write(保存)文件。( fopen php manual)

$f = fopen('/home/www/path/image.jpg', 'w');
fwrite($f, $image);
fclose($f); 
于 2013-09-06T05:58:40.197 回答