Jump to content

save .png to disk


AV1611

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...
Link to comment
https://forums.phpfreaks.com/topic/14126-save-png-to-disk/
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);
?>
Link to comment
https://forums.phpfreaks.com/topic/14126-save-png-to-disk/#findComment-55322
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.
Link to comment
https://forums.phpfreaks.com/topic/14126-save-png-to-disk/#findComment-55458
Share on other sites

Archived

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

×
×
  • Create New...

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.