AV1611 Posted July 9, 2006 Share Posted July 9, 2006 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 file3. 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... Quote Link to comment https://forums.phpfreaks.com/topic/14126-save-png-to-disk/ Share on other sites More sharing options...
Barand Posted July 9, 2006 Share Posted July 9, 2006 does this work, not able to test[code]<?php$im = imagecreatefrompng($theurl);imagepng ($im, 'mypic.png');imagedestroy($im);?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/14126-save-png-to-disk/#findComment-55317 Share on other sites More sharing options...
AV1611 Posted July 9, 2006 Author Share Posted July 9, 2006 Barand, I don't see how that will save the file to disk? Quote Link to comment https://forums.phpfreaks.com/topic/14126-save-png-to-disk/#findComment-55318 Share on other sites More sharing options...
ShogunWarrior Posted July 9, 2006 Share Posted July 9, 2006 <?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 filenamereadfile($file);?> Quote Link to comment https://forums.phpfreaks.com/topic/14126-save-png-to-disk/#findComment-55322 Share on other sites More sharing options...
AV1611 Posted July 10, 2006 Author Share Posted July 10, 2006 still won't do it...The file is on a remote server, the destination is on a local server... Quote Link to comment https://forums.phpfreaks.com/topic/14126-save-png-to-disk/#findComment-55326 Share on other sites More sharing options...
Barand Posted July 10, 2006 Share Posted July 10, 2006 [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 Quote Link to comment https://forums.phpfreaks.com/topic/14126-save-png-to-disk/#findComment-55332 Share on other sites More sharing options...
AV1611 Posted July 10, 2006 Author Share Posted July 10, 2006 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... Quote Link to comment https://forums.phpfreaks.com/topic/14126-save-png-to-disk/#findComment-55439 Share on other sites More sharing options...
heckenschutze Posted July 10, 2006 Share Posted July 10, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/14126-save-png-to-disk/#findComment-55458 Share on other sites More sharing options...
AV1611 Posted July 10, 2006 Author Share Posted July 10, 2006 My Hero ;DI haven't tried it yet, but that looks like what I need... I'll let you know! Quote Link to comment https://forums.phpfreaks.com/topic/14126-save-png-to-disk/#findComment-55463 Share on other sites More sharing options...
Koobi Posted July 10, 2006 Share Posted July 10, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/14126-save-png-to-disk/#findComment-55472 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.