Page 1 of 1
saving a dynamically generated image to database
Posted: Mon Mar 28, 2011 6:59 pm
by RCstp
I have php code to get data from a database and put data into the database. The database is mySQL. The url below dynamically generates an image. I would like to save that image and put it into the database. Any ideas for saving the image that I see on the browser? If I right-click the image in the browser, I can use 'save-as' to save it to my hard drive, but I would like to do this through code.
http://chart.finance.yahoo.com/t?s=MMM& ... height=180
Thanks for your advice.
Re: saving a dynamically generated image to database
Posted: Mon Mar 28, 2011 7:33 pm
by fugix
try using simply the copy() function...copy(file,to_file)
Re: saving a dynamically generated image to database
Posted: Mon Mar 28, 2011 8:18 pm
by RCstp
do you mean like this:
copy(
http://chart.finance.yahoo.com/t?s=MMM& ... height=180,
http://mywebsite.com/test.gif)
or
copy(
http://chart.finance.yahoo.com/t?s=MMM& ... height=180,c:\mypictures\test.gif)
maybe like this ??
<?php
$contents = file_get_contents('
http://chart.finance.yahoo.com/t?s=MMM& ... height=180');
$newcopy = "
http://mywebsite.com/test.gif";
copy($contents,$newcopy);
?>
Re: saving a dynamically generated image to database
Posted: Mon Mar 28, 2011 8:28 pm
by fugix
yes I believe that the last snippet of code that you have there should work
Re: saving a dynamically generated image to database
Posted: Mon Mar 28, 2011 9:26 pm
by litebearer
Or...
Code: Select all
<?PHP
$file1="http://chart.finance.yahoo.com/t?s=MMM&";
$file2=file_get_contents($file1);
file_put_contents("mmm.png", $file2);
?>
<img src="mmm.png" alt="">