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.
saving a dynamically generated image to database
Moderator: General Moderators
Re: saving a dynamically generated image to database
try using simply the copy() function...copy(file,to_file)
Re: saving a dynamically generated image to database
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);
?>
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
yes I believe that the last snippet of code that you have there should work
-
litebearer
- Forum Contributor
- Posts: 194
- Joined: Sat Mar 27, 2004 5:54 am
Re: saving a dynamically generated image to database
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="">