Jump to content


Photo

save .png to disk


  • Please log in to reply
9 replies to this topic

#1 AV1611

AV1611
  • Members
  • PipPipPip
  • Advanced Member
  • 997 posts

Posted 09 July 2006 - 11:03 PM

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

#2 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,021 posts

Posted 09 July 2006 - 11:20 PM

does this work, not able to test

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

If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#3 AV1611

AV1611
  • Members
  • PipPipPip
  • Advanced Member
  • 997 posts

Posted 09 July 2006 - 11:24 PM

Barand, I don't see how that will save the file to disk?

#4 ShogunWarrior

ShogunWarrior
  • Members
  • PipPipPip
  • Advanced Member
  • 528 posts
  • LocationIreland

Posted 09 July 2006 - 11:48 PM

<?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);
?>
<a href="http://www.daviddora...nmedia.com/">My New Site/Blog</a> | <a href="http://www.daviddora...m/check/">Check your page for broken links/images/scripts</a>

Zend Certified Engineer
Follow me on Twitter: http://twitter.com/davidd

#5 AV1611

AV1611
  • Members
  • PipPipPip
  • Advanced Member
  • 997 posts

Posted 10 July 2006 - 12:12 AM

still won't do it...

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

#6 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,021 posts

Posted 10 July 2006 - 12:38 AM

Barand, I don't see how that will save the file to disk?


http://www.php.net/imagepng
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#7 AV1611

AV1611
  • Members
  • PipPipPip
  • Advanced Member
  • 997 posts

Posted 10 July 2006 - 09:45 AM

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

#8 heckenschutze

heckenschutze
  • Members
  • PipPipPip
  • Advanced Member
  • 257 posts
  • LocationAustralia

Posted 10 July 2006 - 10:53 AM

If I understand your question correctly...

<?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";
}
?>


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.



hth, Zac.

#9 AV1611

AV1611
  • Members
  • PipPipPip
  • Advanced Member
  • 997 posts

Posted 10 July 2006 - 11:06 AM

My Hero  ;D

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

#10 Koobi

Koobi
  • Staff Alumni
  • Advanced Member
  • 419 posts
  • LocationColombo, Sri Lanka | South Asia

Posted 10 July 2006 - 11:22 AM

isn't this thread about the same thing:
save img

the solution i posted should work for you.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users