1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Trying to save images from website, but filenames are all the same?

Discussion in 'PHP & Perl' started by ghettogong, Dec 8, 2010.

  1. ghettogong

    ghettogong Regular Member

    Joined:
    Oct 7, 2009
    Messages:
    299
    Likes Received:
    28
    Guys, how is this done?

    I am trying to save product images with the normal right click AND through the page info -> media manager in Firefox from a website of someone else. But as soon as I save the image, the same filename appears in the filename box for every single image.

    How is this done? is it a simple .php script? I can show the site..

    Thanks
    GhettoGong
     
    Last edited: Dec 8, 2010
  2. Simkaa

    Simkaa Newbie

    Joined:
    Jun 22, 2010
    Messages:
    5
    Likes Received:
    3
    Show the site please, for that info what you provided.. can't tell anything.
     
    • Thanks Thanks x 1
  3. ghettogong

    ghettogong Regular Member

    Joined:
    Oct 7, 2009
    Messages:
    299
    Likes Received:
    28
    Hi, sorry, yeah check this site out and try to the save image....the filename will always remain for all images: media.l??dsworld.com.jpg

    Check the url's
    Replace ? with e

    Random product: http://www.l??dsworld.com/products/item/?item=4200-12

    or look at any of their products: http://www.l??dsworld.com/products/

    How can they show different images on their site when all the images have the same filename?
     
  4. Simkaa

    Simkaa Newbie

    Joined:
    Jun 22, 2010
    Messages:
    5
    Likes Received:
    3
    Actually the images are taken all with some code (php, asp depends)

    The actual image URL is URL_HERE/ms/?/regular/4200-12/en and URL_HERE/ms/?/regular/8200-27/en

    When you click "download", then the script just outputs a file with the same name (media.leeds..). When you try to same images from direct image link, then you can get the filename download.jpg


    Nothing hard to do this, but pretty useful when people want's to save their images in bulk :)
     
    • Thanks Thanks x 1
  5. ghettogong

    ghettogong Regular Member

    Joined:
    Oct 7, 2009
    Messages:
    299
    Likes Received:
    28
    Exactly, unless you click on the download link you will get the exact filename of the image. (my shop does not have a download link, so no problem)

    I also want to try and acomplish that all my images outputs the same filename (media.l??ds...), could you help please me where I could get more info on this issue? :)
     
  6. coderjeff

    coderjeff Junior Member

    Joined:
    Nov 20, 2007
    Messages:
    130
    Likes Received:
    26
    Location:
    USA
    Basically, all it requires is having your script send a header that tells the browser that it is returning an image. If the script is test.php, the browser will save the image as test.php.jpg

    Code:
    <?php
       header('Content-Type: image/jpeg');
       echo  file_get_contents('image4821.jpg');
    A rewrite rule in your htaccess file can convert the different image urls into a call to your script, and the script will need to get the actual filename based upon the url.

    With the GD2 library, PHP can also manipulate or resize images so your script can return different sized thumbnails from one saved imaged. This is probably what the site you mentioned is doing. The resulting filename is the natural outcome when using a script to create different image sizes on the fly.
     
    • Thanks Thanks x 1
  7. Samsonette

    Samsonette Newbie

    Joined:
    Jan 19, 2009
    Messages:
    23
    Likes Received:
    632
    Gender:
    Female
    Occupation:
    retired - but extremely active ;-)
    Location:
    ô¿Ô I see all I shouldn't
    Why don't you use the not normal way and left click the picture you like, hold it and drag it to you Desktop? :)

    Each time I do this with your given url, I have to rename that picture, because all are named as " .jpg " only.

    Advantage: you deleted a possible footprint with your new name given.
     
    • Thanks Thanks x 1
  8. ghettogong

    ghettogong Regular Member

    Joined:
    Oct 7, 2009
    Messages:
    299
    Likes Received:
    28
    Allright that seems easy. I run a Joomla Virtuemart store, could you help me set this thing up against a paypal donation ofcourse ;-) (thanks given)

    You have taken the words out of my mouth. Literally that is what I want, to erase the footprints! (thanks given)
     
  9. ghettogong

    ghettogong Regular Member

    Joined:
    Oct 7, 2009
    Messages:
    299
    Likes Received:
    28
    I dont know if you got my pm, but I would like to know how to get it working. I found this forum what is kind of similar to my wish: http://www.phpbuilder.com/board/archive/index.php/t-10263028.html

    Maybe you can tell me if this is correct on how to do it?

    1. Create a .php file with the code you gave and FTP in to the root of the site.
    2. Duplicate this code for each image name: echo file_get_contents('image4821.jpg');
    3. Then add a rewrite rule in htaccess file, I dont know which rule?

    Is this correct?
     
  10. coderjeff

    coderjeff Junior Member

    Joined:
    Nov 20, 2007
    Messages:
    130
    Likes Received:
    26
    Location:
    USA
    You can do it with a single php file by passing part of the image file name as a parameter. Gimme a bit, and I'll post sample code later today.
     
  11. coderjeff

    coderjeff Junior Member

    Joined:
    Nov 20, 2007
    Messages:
    130
    Likes Received:
    26
    Location:
    USA
    Here's a quick and easy way to do it.

    Create an images subdirectory to hold your images and a php file

    img.php
    Code:
    <?php
       $img = '';
       if ($_REQUEST)
         $img = array_pop(array_keys($_REQUEST));
       $file = "image$img.jpg";
       if (is_file($file)) {
         header('Content-Type: image/jpeg');
         echo file_get_contents($file);
    	 }
    Use code like this in your html to request the images
    Code:
    <img src='images/img.php?4821'>
    The img.php code will convert 4821 into image4821.jpg (to hide the acutal filename) and return the image4821.jpg display it. You can change the suffix or you could use a database to lookup the actual filename, but this should give you a starting point.

    You'll also want to have a blank index.html or index.php file in the subdirectory so nothing shows up if someone accesses it directly.

    Hope this helps
     
    • Thanks Thanks x 1
  12. sarahparker

    sarahparker BANNED BANNED

    Joined:
    Dec 17, 2010
    Messages:
    13
    Likes Received:
    0
    I guess that is a problem with your download handler software or if it's direct download then try switching your browser.
     
  13. ghettogong

    ghettogong Regular Member

    Joined:
    Oct 7, 2009
    Messages:
    299
    Likes Received:
    28
    Million thanks! Correct me if i am wrong in green:

    And to clarify your method. For example when I want to save that product (4821) or any other product on my site it will have as filename: "img" right? Because that is what i am trying to accomplish here. Outputting all image names with the same image name so I erase my footprints.
     
  14. coderjeff

    coderjeff Junior Member

    Joined:
    Nov 20, 2007
    Messages:
    130
    Likes Received:
    26
    Location:
    USA
    Instead of
    Code:
    wwwyoursite/images/image1234.jpg
    You use
    Code:
    wwwyoursite/images/img.php?1234
    A right-click download will be named something like 'img.php.jpg' for all of the images.

    You should be able to test things by simply putting the image url in your browser before you add the url to Virtuemart.
     
  15. ghettogong

    ghettogong Regular Member

    Joined:
    Oct 7, 2009
    Messages:
    299
    Likes Received:
    28
    Feeling like shit right now, such a simple method and still I cannot retrieve the image.

    1. I have put the code and saved it as img.php and uploaded in the root of the domain.
    2. Uploaded a .jpg file in the same root.
    3. When i call the url like: www.domain.com/img.php?12345 nothing appears on screen.

    I can't be missing out of something right? You said something about a rewrite rule in .htacces, do i still need to do that?
     
    Last edited: Dec 22, 2010
  16. coderjeff

    coderjeff Junior Member

    Joined:
    Nov 20, 2007
    Messages:
    130
    Likes Received:
    26
    Location:
    USA
    This simple script doesn't need the rewrite rule. If you used the script as-is, if you browse to www.domain.com/img.php?12345 it should display the image named image12345.jpg
     
  17. ghettogong

    ghettogong Regular Member

    Joined:
    Oct 7, 2009
    Messages:
    299
    Likes Received:
    28
    yeah, thats the stupid things, its so simple. If i browse to /img.php? nothing appears even in the source code, so strange?!? The permission on img.php and the image are 644 but still no result.

    P.S please send me your paypal id for beer money :) I will then send you the site we are talking about.
    Posted via Mobile Device
     
  18. coderjeff

    coderjeff Junior Member

    Joined:
    Nov 20, 2007
    Messages:
    130
    Likes Received:
    26
    Location:
    USA
    PM sent