October 16th, 2013, 06:27 PM
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:
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:
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?
October 16th, 2013, 07:02 PM
What happens if you comment out the Content-Type header and browse directly to orange.jpg?
October 16th, 2013, 07:58 PM
No difference. just the image alt text
Originally Posted by requinix
October 16th, 2013, 08:04 PM
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.
October 16th, 2013, 08:40 PM
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.
October 16th, 2013, 09:31 PM
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?
October 16th, 2013, 09:54 PM
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
October 16th, 2013, 10:58 PM
Firefox has the Firebug extension which does practically the same things.