Re: [PHP] Downloading Images
John Camp wrote: I was able to successfully make a very simple http proxy - turns out the php documentation has the code for this =] - but now I need a way to display images. I figured the best way would be to download the images to a temporary folder, then parse the html to point to the images on my server instead. The problem is that I do not know how to download the images. $imgdata = file_get_contents("http://somedomain.com/someimage.jpg";); but this assumes that your php setup has the allow_url_fopen ini setting set to true/1, see here for more info: http://nl2.php.net/manual/en/ref.filesystem.php#ini.allow-url-fopen if not then the only other way _I_ can think of, using PHP, is using the cURL extension - which maynot be available either :-S Also if anyone has a link to a parsing script it would save a good amount of time. regexps is the way to go, I did a quick google and found this post: http://forums.devshed.com/t173149/s.html&highlight=parse+image there is a little code snippet there which might be a starting point for you. here is an untested regexp which goes a little further, it assumes that the img tags have the src attr properly delimited and specifically delimited with doublequotes. |]*src="([^"]*)"[^>]*>|i hope that helps you on your way. (hey list-guys! look no rtfm'ing in sight!) Thanks for any help. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Downloading Images
On Wed, 12 Jan 2005 22:14:35 -0600, John Camp <[EMAIL PROTECTED]> wrote: > I was able to successfully make a very simple http proxy - turns out the > php documentation has the code for this =] - but now I need a way to > display images. I figured the best way would be to download the images > to a temporary folder, then parse the html to point to the images on my > server instead. The problem is that I do not know how to download the > images. > > Also if anyone has a link to a parsing script it would save a good > amount of time. wget can download/mirror an entire site for you, has proxy support, and it will update the image paths as well. One little command is all you need: wget -m -np http://example.com/ -- Greg Donald Zend Certified Engineer http://destiney.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Downloading Images
I was able to successfully make a very simple http proxy - turns out the php documentation has the code for this =] - but now I need a way to display images. I figured the best way would be to download the images to a temporary folder, then parse the html to point to the images on my server instead. The problem is that I do not know how to download the images. Also if anyone has a link to a parsing script it would save a good amount of time. Thanks for any help. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] downloading images
With some of the newer broswers, you may be able to re-define the functionality of the context menu via JavaScript. Visit http://www.dynamicdrive.com; I think that there are some examples there, and you might be able to redirect the "save image as..." functionality there (I wouldn't count on it, though). Another option might be to zip up the larger image as a zip file and create a link to that zip file through the thumbnail image. That way, when the user clicks on the thumbnail, they are prompted with a "save as..." dialogue box and they can then save the document on their own computer. They still have to unzip it though. Other than that, I think you're out of luck. The problem is that saving an image onto a computer is a client-side function, which you can have no control over with server-side programs such as PHP or Perl. If you can come up with a way for a web page to mess around with the source code of Netscape or IE, then you might be able to do things like control the "save image as..." functionality, or disable the back button, but that seems pretty unlikely to me. At 10:47 AM 10/29/2001, you wrote: >Hey, >I'd like users to be able to download images from on >my site. The images are pretty big, so i've made >thumbnails for each. I can display each thumbnail, >but how can i get it so that once the user clicks on >the thumbnail, they get to download the whole image. >I'd like it to work without having the user to right >click and choose 'save image as'. >Any ideas?! >Thanks, >Heidi Sliante, Richard S. Crawford http://www.mossroot.com mailto:[EMAIL PROTECTED] AIM: Buffalo2K ICQ: 11646404 Y!: rscrawford "It is only with the heart that we see rightly; what is essential is invisible to the eye." --Antoine de Saint Exupéry "Push the button, Max!" -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] Downloading Images
I suggest you call: readfile() instead of include() at the end of your script! "David Otton" <[EMAIL PROTECTED]> wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... > On Thu, 4 Oct 2001 07:32:17 -0700 (PDT), you wrote: > > >I have added a download button to a web-site that > >enables users to download images to their local > >drives. (I'm using a button as I want to wrap some > >logic round this function) I have the following > >(simplified code )that will be called from the > >web-site when the button is clicked. > > > >header("Content-type: application/octet-stream"); > >header( "Content-Disposition: attachment; > >filename=01lg.jpg"); > >$filename= "c:/program files/apache > >group/apache/kidz/gallery/download/01lg.jpg"; > > include($filename); > > > >The result is the SaveAs box appears and the image is > >being downloaded with the correct name however when I > >try and re-open the image i get the message invalid > >header. Does anyone have any ideas? > > What does the downloaded file look like internally? Open it in a hex > editor (or even just Notepad). Check the file-lengths of the original > and copy. My guess is you're saving an error message with a .jpeg > extension. > > djo > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] Downloading Images
On Thu, 4 Oct 2001 07:51:59 -0700 (PDT), you wrote: >different length, (3k as opposed to the original 9k) I >originally did have an error message appended to the >downloaded image but that no longer appears to be the >case. However the image is definitely truncated. Any All the JPEGs I have here end with (FF D9), as does yours. However, it's missing the header (which starts (FF D8) and has the string JFIF in it.) I would guess you're only saving the last 2497 bytes of the file to disc. As to why... maybe your script isn't seperating headers and body properly, and a big chunk of file is being thrown away by the browser as an unrecognised "header"? >ideas why this may be happening? Please find attached >downloaded image. BTW, I'm not sure that sending binaries to a discussion list is a bright idea. djo -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] Downloading Images
Hi Dave, Thanks for you prompt response. The Image is indeed a different length, (3k as opposed to the original 9k) I originally did have an error message appended to the downloaded image but that no longer appears to be the case. However the image is definitely truncated. Any ideas why this may be happening? Please find attached downloaded image. Thanks, Roger --- David Otton <[EMAIL PROTECTED]> wrote: > On Thu, 4 Oct 2001 07:32:17 -0700 (PDT), you wrote: > > >I have added a download button to a web-site that > >enables users to download images to their local > >drives. (I'm using a button as I want to wrap some > >logic round this function) I have the following > >(simplified code )that will be called from the > >web-site when the button is clicked. > > > >header("Content-type: application/octet-stream"); > >header( "Content-Disposition: attachment; > >filename=01lg.jpg"); > >$filename= "c:/program files/apache > >group/apache/kidz/gallery/download/01lg.jpg"; > > include($filename); > > > >The result is the SaveAs box appears and the image > is > >being downloaded with the correct name however when > I > >try and re-open the image i get the message invalid > >header. Does anyone have any ideas? > > What does the downloaded file look like internally? > Open it in a hex > editor (or even just Notepad). Check the > file-lengths of the original > and copy. My guess is you're saving an error message > with a .jpeg > extension. > > djo > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: > [EMAIL PROTECTED] > For additional commands, e-mail: > [EMAIL PROTECTED] > To contact the list administrators, e-mail: > [EMAIL PROTECTED] > __ Do You Yahoo!? NEW from Yahoo! GeoCities - quick and easy web site hosting, just $8.95/month. http://geocities.yahoo.com/ps/info1 <> -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] Downloading Images
On Thu, 4 Oct 2001 07:32:17 -0700 (PDT), you wrote: >I have added a download button to a web-site that >enables users to download images to their local >drives. (I'm using a button as I want to wrap some >logic round this function) I have the following >(simplified code )that will be called from the >web-site when the button is clicked. > >header("Content-type: application/octet-stream"); >header( "Content-Disposition: attachment; >filename=01lg.jpg"); >$filename= "c:/program files/apache >group/apache/kidz/gallery/download/01lg.jpg"; > include($filename); > >The result is the SaveAs box appears and the image is >being downloaded with the correct name however when I >try and re-open the image i get the message invalid >header. Does anyone have any ideas? What does the downloaded file look like internally? Open it in a hex editor (or even just Notepad). Check the file-lengths of the original and copy. My guess is you're saving an error message with a .jpeg extension. djo -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP] Downloading Images
All, I have searched high and low through the lists to find a solution to this problem but none of the suggestions appear to work for me. I have added a download button to a web-site that enables users to download images to their local drives. (I'm using a button as I want to wrap some logic round this function) I have the following (simplified code )that will be called from the web-site when the button is clicked. header("Content-type: application/octet-stream"); header( "Content-Disposition: attachment; filename=01lg.jpg"); $filename= "c:/program files/apache group/apache/kidz/gallery/download/01lg.jpg"; include($filename); The result is the SaveAs box appears and the image is being downloaded with the correct name however when I try and re-open the image i get the message invalid header. Does anyone have any ideas? Vesrions are PHP 3,IE6, Windows ME. Thanks very much in advance, Roger __ Do You Yahoo!? NEW from Yahoo! GeoCities - quick and easy web site hosting, just $8.95/month. http://geocities.yahoo.com/ps/info1 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] Downloading images through the use of code
>First of all, am I correct in assuming I could download a file and parse it using fopen("url")? Yup. Pretty darn nifty, huh? >Secondly, if I find an IMG tag, how would I go about grabbing the file that is contained in the SRC of that image tag? >Would another simple fopen() and fput() to another file work with that, or is there an easier way? Yup, another fopen() and fgets() and away you go -- You snarfed the image. You'll have to be kinda careful about your urls and files and not trip over your own feet having two of each of them open at the same time, though. :-) I'd say use $htmlurl and $imgurl, and $htmlfile and $imgfile to keep 'em straight. >if(str_replace("IMG SRC", "", $newline) != $newline) { This won't catch those heathens using lowercase or MixedCase for their HTML tags. While they deserve to burn in hell for it, I reckon you probably would rather work with them while they're still here on Earth. It also won't catch any heretics doing something wacky like , which is, of course, totally immoral, even if it does match HTML spec. if (stristr($newline, "http://www.zend.com Wanna help me out? Like Music? Buy a CD: http://l-i-e.com/artists.htm Volunteer a little time: http://chatmusic.com/volunteer.htm -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP] Downloading images through the use of code
I have a question for a friend of mine (yes, it's actually for a friend of mine). Here is my code below. First of all, am I correct in assuming I could download a file and parse it using fopen("url")? Secondly, if I find an IMG tag, how would I go about grabbing the file that is contained in the SRC of that image tag? Would another simple fopen() and fput() to another file work with that, or is there an easier way? $file = fopen("http://url"); while(!feof($file)) { $newline = fgets($file); if(str_replace("IMG SRC", "", $newline) != $newline) { /*do stuff*/ } } Thanks a lot everyone! Liam...