Jump to content

Archived

This topic is now archived and is closed to further replies.

AV1611

save .png to disk

Recommended Posts

I can't figure out how to do this...

1.  I have a script on a remote server that creates .png files dynamically.
2.  I know the name and url to the file
3.  I need to grab that .png and save it on my local server with a php script.

I tried file_get_contents, fopen, etc, but can't make a working script that will retrieve a .png from url and save to local disk...

Please help...

Share this post


Link to post
Share on other sites
does this work, not able to test

[code]
<?php
$im = imagecreatefrompng($theurl);
imagepng ($im, 'mypic.png');
imagedestroy($im);
?>[/code]

Share this post


Link to post
Share on other sites
Barand, I don't see how that will save the file to disk?

Share this post


Link to post
Share on other sites
<?php
$file = 'file.png';

    header("Content-type: image/force-download");
    header("Content-Disposition:  attachment; filename=\"$file\"");
    header("Pragma: public");
    header("Cache-control: private");
    header("Content-transfer-encoding: binary\n");
    header("Content-length: ".(string)(filesize($file)));
    header("Expires: 0");
    header("Pragma: no-cache");

//Change filename
readfile($file);
?>

Share this post


Link to post
Share on other sites
still won't do it...

The file is on a remote server, the destination is on a local server...

Share this post


Link to post
Share on other sites
[quote author=AV1611 link=topic=99996.msg394171#msg394171 date=1152487468]
Barand, I don't see how that will save the file to disk?
[/quote]

http://www.php.net/imagepng

Share this post


Link to post
Share on other sites
I've read the link, and know the answer is there somewhere, but I can't find it...

Can someone help?

I need the php script on the local server to save to disk the .png that is generated by the script on the remote server...

Share this post


Link to post
Share on other sites
If I understand your question correctly...

[code]<?php
$strSource = "http://myremoteserver.com/images/mypng.png";
$strDest = "./images/mypng.png";

if(copy($strSource, $strDest))
{
echo "Copied file!";
}else{
echo "Failed to copy file";
}
?>[/code]


[quote]Note:  As of PHP 4.3.0, both source and dest may be URLs if the "fopen wrappers" have been enabled. See fopen() for more details. If dest is a URL, the copy operation may fail if the wrapper does not support overwriting of existing files.[/quote]


hth, Zac.

Share this post


Link to post
Share on other sites
My Hero  ;D

I haven't tried it yet, but that looks like what I need...  I'll let you know!

Share this post


Link to post
Share on other sites
isn't this thread about the same thing:
[url=http://www.phpfreaks.com/forums/index.php/topic,99916.0.html]save img[/url]

the solution i posted should work for you.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.