![]() |
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. :) |
Re: Downloading an external image and saving it to disk
Can you post your current code?
|
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.
|
Re: Downloading an external image and saving it to disk
Quote:
|
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?
|
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. |
Re: Downloading an external image and saving it to disk
Quote:
|
| 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