Jump to content

Download Image from URL and Upload it


MasterK

Recommended Posts

Ok, I have been googling for the last 1/2 hour trying to figure this out, Most likely I'm just not searching for the right thing.

 

Here is what I want to do.

 

I want to have a Text box which somebody will paste a URL into. The URL will be a PHP Image (Example)

 

Now I want it to download that image as a JPEG to my Website, and name it that last 6 numbers of the URL (for the Example about it would be 185950.jpeg)

 

Then I want it to redownload, and name it every 20minutes

 

I just need pointed in the right direction here, because my Google searches are turning up nothing at all  :-[

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/179141-download-image-from-url-and-upload-it/
Share on other sites

Ok, So I was frustrated and before anybody had replied, I figured eh, What the heck, Imma try something crazy! and it WORKED!

 

Here is what I am talking about.

 

$url = "http://photo.playerdex.com/trainercard.php?ID=";

$ourFileName = "$str.jpeg";
$ourFileHandle = fopen($ourFileName, 'w')
fclose($ourFileHandle);


$link = $url.$str;
$source = file_get_contents($link);
$myFile = "images/tc/$ourFileName";
$fh = fopen($myFile, 'w')
fwrite($fh, $source);
fclose($fh);

 

I did not think this would work, But I thought I would try it anyways, and it works! This might not be surprising to many people, but I was surprised.

 

Now I just need to get the Cronjob setup, I need to figure out how to make it update all the images that have been created..  :P::)

Now I just need to get the Cronjob setup, I need to figure out how to make it update all the images that have been created..  

 

Continually update an image that hasnt changed?? I thought i was bored :-\

 

lol?

 

Who said it didn't change? Not I...

 

The image is generated from a Database based on your current team in the game, It updates quite often  :P

Archived

This topic is now archived and is closed to further replies.

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