Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.