#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2013
    Posts
    4
    Rep Power
    0

    Red face Php readfile & htaccess rewrite


    I am fairly confident in PHP. I just got on a web hosting site and am trying to get adaptive-images to work. I have possibly narrowed my problem down to the rewrite rull, or the php readfile command.

    In my .htaccess, I have 2 lines:
    RewriteEngine On
    RewriteRule \.(?:jpe?g|gif|png)$ t3.php

    In my HTML, the only line if have (excluding tags) is:
    <img src="orange.jpg" alt="jpeg alt" >

    My t3.php is short:
    <?php
    $filename= green.jpg';
    header('Content-type: image/jpeg');
    header('Content-transfer-encoding: binary');
    header('Content-length: '.filesize($filename));
    readfile($filename);
    ?>

    If I understand the rewrite rule, instead of displaying orange.jpg, I should display green.jpg.
    Both jpegs exist. Without the rewriterule, orange is displayed. With the rule, the alt text is displayed.
    Am I correct in assuming that the rewrite rule will detect the .jpg, and call t3.php?
    What does it mean that t3.php ‘sends’ back (readfile) green.jpg?
    And what exactly does the readfile (in php) and the image tag do together in this example?
  2. #2
  3. Did you steal it?
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    13,959
    Rep Power
    9397
    What happens if you comment out the Content-Type header and browse directly to orange.jpg?
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2013
    Posts
    4
    Rep Power
    0
    Originally Posted by requinix
    What happens if you comment out the Content-Type header and browse directly to orange.jpg?
    No difference. just the image alt text
  6. #4
  7. Did you steal it?
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    13,959
    Rep Power
    9397
    You will not see "jpeg alt" if you're going to the place I'm saying.

    I mean navigate directly to "orange.jpg". Not the page where you have the <img> tag, and not t3.php either.
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2013
    Posts
    4
    Rep Power
    0
    Thanks requinix for your help.

    I understand what you are saying, and yes, that does work.
    However, I am trying to get a PHP script 'adaptive-images.php' to work.
    when called by the rewrite rule, it takes the file name 'orange.jpg', determines the size of the client (designed to work with images on mobile devices), creates a copy of the image close to the dimensions of the mobile device, saves it and passes the name of the file with the PHP readfile(...) command.
    that is the part that is not working.
    Any ideas?
  10. #6
  11. Did you steal it?
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    13,959
    Rep Power
    9397
    I know what you're trying to do. I wanted to see if the call to "orange.jpg" by itself works. Because 99% of the time when the alt text is shown the reason is that the image itself is broken.

    If the image works correctly, which apparently it does, then there's no particular reason why the browser should show the alt text. Use whatever tools your browser has to look at all the requests it's making when it loads the original page (the one with the <img>, this time). For instance, hit F12 in Chrome, go to the Network tab, and then load the page. In there will be the request for the image. What does it say happened?
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2013
    Posts
    4
    Rep Power
    0
    thanks again. I use Firefox. I will load chrome in the
    morning and see what it says.
    I will let you know.
    Thanks again for your help
  14. #8
  15. Did you steal it?
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    13,959
    Rep Power
    9397
    Firefox has the Firebug extension which does practically the same things.

IMN logo majestic logo threadwatch logo seochat tools logo