Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   PHP (http://www.programmingforums.org/forum29.html)
-   -   Downloading an external image and saving it to disk (http://www.programmingforums.org/showthread.php?t=14354)

Jessehk Nov 6th, 2007 10:50 PM

Downloading an external image and saving it to disk
 
Hi all. I'm a maintainer for my school's website and recently, a teacher had put forward a request. He wants the website to download an image every hour and save it to disk.

This might be a stupid question, but is this sort of thing possible in PHP? I've attempted to put together something quickly using the copy() function and the Google logo, but I'm getting permission errors when I attempt to write the image to disk.

Am I approaching this the correct way, or is there something that I'm missing? I'm not looking for a specific solution, but some general direction of how to proceed would be really appreciated. :)

Wizard1988 Nov 6th, 2007 11:24 PM

Re: Downloading an external image and saving it to disk
 
Can you post your current code?

PhilBon Nov 7th, 2007 2:29 AM

Re: Downloading an external image and saving it to disk
 
Make sure that you have access to write to that folder. Most the time on PHP servers the only access for the end users is read only. Run through your code and if you know that you are getting stopped at the writing part, chances are it's that the permissions have not been set up.

Jessehk Nov 7th, 2007 10:11 PM

Re: Downloading an external image and saving it to disk
 
Quote:

Originally Posted by PhilBon (Post 136390)
Make sure that you have access to write to that folder. Most the time on PHP servers the only access for the end users is read only. Run through your code and if you know that you are getting stopped at the writing part, chances are it's that the permissions have not been set up.

My only concern was that if I set write permission for a specific folder (even if it was just for containing the image downloads in question), it would be insecure. Is there any reason that I should avoid doing that?

Ghost Nov 7th, 2007 11:08 PM

Re: Downloading an external image and saving it to disk
 
I program in .Net so I'd more than likely make a service or shedule a task to run every hour and download on the server, is that possible for you to do?

Sane Nov 8th, 2007 12:53 AM

Re: Downloading an external image and saving it to disk
 
There are operations for accessing an external web page internally. You could do this with raw sockets even if you have to (Connect to the server, Request the image, Receive the image, Cast some black magic).

Make sure to use the correct header information to request the image (GET /myimage.jpg HTTP/1.1\r\nHost: mywebsite.com\r\nContent-type: image/jpeg\r\n\r\n), and then use your file IO functions (Open File, Write to File, What the hell does this do?) with a binary write stream to save the image locally.

Then, of course, automate this with an hourly crontab.

Dameon Nov 8th, 2007 9:11 AM

Re: Downloading an external image and saving it to disk
 
Quote:

Originally Posted by Jessehk (Post 136438)
My only concern was that if I set write permission for a specific folder (even if it was just for containing the image downloads in question), it would be insecure.

It would be much nicer if you could save the image to disk without writing to it, hmm?


All times are GMT -5. The time now is 3:20 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC