Forum Moderators: coopster

Message Too Old, No Replies

images outside of htdocs sans $ GET

         

Dunjohn19

7:07 pm on Aug 7, 2020 (gmt 0)

5+ Year Member



i am hoping someone can offer help showing images outside of htdocs (apache) without using $_GET.
here is example code.

html page with image citing image.php as src
<html>
<head>
<title></title>
<link rel="stylesheet" type="text/css" href="index.css">
</head>
<body>

<img src="image.php" alt="" width="500" height="300">

</body>
</html>


image.php
//we can even require this code from outside root and it works
//i just can't find a way to make variables work with this code
//i've even tried $GLOBAL variables with failure.
$file = "test/image.jpg"; }
header("Content-Type: image/jpeg");
header("Content-Length: " . filesize($file));
readfile($file);


now $_GET['image'] works if image source is image.php?image=image.jpg
i don't want to use $_GET[]. I'd like to use a variable or pass a var to a function.
i've tried this and it only works for one image hardcoded function_name('image');
i've even tried using a session variable and it fails for all images using the function.

is it possible to use one php file to load all images or do i need to create a php fetch script for each image?

again, i don't want to use $_GET[] and i don't want to discuss using $_GET[]. my method works fine but only for one image.
perhaps a buffer solves the session variable problem? any ideas? please?

Thank you.

nordberg25

11:01 am on Aug 9, 2020 (gmt 0)

5+ Year Member



Include your image.php file declare a new variable and make it equal to variable in image.php file
<?php include "image.php"; 
$img = $file;?>

<html>
<head>
<title></title>
<link rel="stylesheet" type="text/css" href="index.css">
</head>
<body>
echo new image variable here
<img src="<?php echo $img; ?>" alt="" width="500" height="300">


</body>
</html>

image.php page
<?php
$file = "test/image.jpg";

?>


If you are running an html file than I would recommend changing it to a php file as this will not work unless you make some changes to your .htaccess file or conf file <no links please>



[edited by: not2easy at 11:35 am (utc) on Aug 11, 2020]
[edit reason] See Charter [webmasterworld.com] [/edit]

Dunjohn19

4:48 am on Aug 11, 2020 (gmt 0)

5+ Year Member



Hello Nordberg, Thank you for replying. I appreciate you very much.

I've tried this code but it only shows the image and not the html page. I use xampp to develop my site.

i have a folder named test outside of htdocs. so the image will be $file = '../test/image.jpg';

the code works for showing the image but i want the image inline with the rest of the page. I can't seem to find a way to make it work. The variables will allow me to control the images, whereas a GET request opens the door to hacking and security problems. I can't find a way to accomplish this task without using GET requests. I have tried GET requests recently and control method of setting a session variable and unsetting the variable after image has been retrieved. The code works but i'd like to find a way to do this using variables.

have i done something wrong? the method that you post is working only for the image but it could be xampp.

Best wishes and Thank you.

nordberg25

7:38 pm on Aug 19, 2020 (gmt 0)

5+ Year Member



It worked with the code I used perfect on my server, so maybe it's just a setting in xampp. Can you try it on a live server? Although I tested mine on a php page and not an html page. Not sure which one you're using, but yeah via php no problems...worked as expected no $_GET needed