Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Nov 6th, 2007, 9:50 PM   #1
Jessehk
The Oblivious One
 
Jessehk's Avatar
 
Join Date: May 2005
Location: Ontario, Canada
Posts: 644
Rep Power: 4 Jessehk is on a distinguished road
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.
__________________
Dr. Zoidberg: [ecstatic] I'm going to a movie... with FRIENDS!
Jessehk is offline   Reply With Quote
Old Nov 6th, 2007, 10:24 PM   #2
Wizard1988
Professional Programmer
 
Wizard1988's Avatar
 
Join Date: Oct 2005
Location: Chitown
Posts: 417
Rep Power: 4 Wizard1988 is on a distinguished road
Send a message via AIM to Wizard1988
Re: Downloading an external image and saving it to disk

Can you post your current code?
__________________
JG-Webdesign
Wizard1988 is offline   Reply With Quote
Old Nov 7th, 2007, 1:29 AM   #3
PhilBon
Hobbyist Programmer
 
PhilBon's Avatar
 
Join Date: Nov 2005
Posts: 172
Rep Power: 3 PhilBon is on a distinguished road
Send a message via AIM to PhilBon Send a message via MSN to PhilBon
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.
PhilBon is offline   Reply With Quote
Old Nov 7th, 2007, 9:11 PM   #4
Jessehk
The Oblivious One
 
Jessehk's Avatar
 
Join Date: May 2005
Location: Ontario, Canada
Posts: 644
Rep Power: 4 Jessehk is on a distinguished road
Re: Downloading an external image and saving it to disk

Quote:
Originally Posted by PhilBon View Post
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?
__________________
Dr. Zoidberg: [ecstatic] I'm going to a movie... with FRIENDS!
Jessehk is offline   Reply With Quote
Old Nov 7th, 2007, 10:08 PM   #5
Ghost
Man Bear Pig Hunter
 
Ghost's Avatar
 
Join Date: Jul 2005
Location: NorCal, USA
Posts: 295
Rep Power: 4 Ghost is on a distinguished road
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?
Ghost is offline   Reply With Quote
Old Nov 7th, 2007, 11:53 PM   #6
Sane
Programming Guru
 
Sane's Avatar
 
Join Date: Apr 2005
Location: Waterloo, Ontario
Posts: 1,886
Rep Power: 5 Sane will become famous soon enough
Send a message via MSN to Sane
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.

Last edited by Sane; Nov 8th, 2007 at 12:06 AM.
Sane is offline   Reply With Quote
Old Nov 8th, 2007, 8:11 AM   #7
Dameon
Troll
 
Dameon's Avatar
 
Join Date: Apr 2005
Location: Texas
Posts: 732
Rep Power: 4 Dameon is on a distinguished road
Re: Downloading an external image and saving it to disk

Quote:
Originally Posted by Jessehk View Post
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?
__________________
MD5(sig) = bcef75433db02e9ad9bf81d6f7c5c270
Dameon is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
manipulating pixels of images and saving them on a file diamondustice Visual Basic 0 Feb 21st, 2006 9:00 PM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 11:03 PM.

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