PHP Link to an image outside the root folder [a href, not img src]

Here is my situation: images are stored outside the root folder. I can access them with an external php file (as it should be), then file_get_contents, then echo, and then img srcit will display perfectly.

I have a thick box installed, and I want this to happen when the user clicks on the image, it will be displayed in a larger size

<a href="img.jpg" class="thickbox"><img src="my_image_processing.php?img=img.jpg" />

I am trying to create a gallery on click. It happens that a thick box appears, but the image does not work. Instead of an image, bar / junk codes appear with black diamonds with a question mark. I assume this is the source code of the image.

How can I output this as an image, not raw code in

<a href> 's

ADDED: I just played a little with him. When I remove the colon class, it actually works a href. It displays the image on the next page. Fortunately, when I attach the thick box classes, it shows the thick box, but it shows the source code

+3
source share
4 answers

In your example, you use the jpg file directly, it should look something like this:

<a href="my_image_processing.php?img=img.jpg" class="thickbox"><img src="my_image_processing.php?img=img.jpg" />

That is, a php page that reads a hidden folder and returns an image.

+2
source

Try:

header ("Content-type: image/jpeg");

If you see the raw image data as text, your browser may not recognize the output as an image. You can signal the correct mime type using the title bar above.

, , ( ). .

+2

Thickbox , , , , . . , :

  • URL- script, . URL my_image_processing/img.jpg my_image_processing.php?img=img.jpg ( "mod_rewrite" ),
  • ThickBox ( , - )
  • , , ( script , ),

, Thickbox , , , - vbence - mime , script: "Content-Type".

EDIT:

, , [sic!]:

var baseURL;
 if(url.indexOf("?")!==-1){ //ff there is a query string involved
  baseURL = url.substr(0, url.indexOf("?"));
 }else{ 
     baseURL = url;
 }

 var urlString = /\.jpg$|\.jpeg$|\.png$|\.gif$|\.bmp$/;
 var urlType = baseURL.toLowerCase().match(urlString);
if(urlType == '.jpg' || urlType == '.jpeg' || urlType == '.png' || urlType == '.gif' || urlType == '.bmp'){//code to show images

, ( "php" ), script, .

EDIT2:

If you go to the "change plugin" option, there is an alternative ( ColorBox ) that allows you to make decisions without having to dig into the code, whether the * .php link should be considered as an image. Just find the option photoin the documentation (when set photo=trueshould behave as you expected).

+1
source

You probably neglected the http headers to display the image.

header("Content-type: image/jpeg");
header("Content-Disposition: attachment;"); 
0
source

All Articles