...

View Full Version : Making a small page



jfreak53
10-22-2004, 10:17 PM
I need a small PHP driven page that will do one and only one thing, I need it to keep a list of certain images I have in a directory and when I call it with a certain parameter display that image as a page with some code I add after words, basically all it has to be is an image display page, I need the full code for this if anyone can help please?

marek_mar
10-22-2004, 10:48 PM
Fell free to dress it with HTML


<?php
// This is the directory in which the images reside.
$dir = "/tmp/";

// Open a known directory, and proceed to read its contents
if (is_dir($dir)) {
if ($dh = opendir($dir)) {
while (($file = readdir($dir)) !== false) {
if( preg_match('/^\.(bmp|jpe?g|gif|png)$/i', $extension) ) { // check the file is an image
echo $dir . $filename; // if it is, add it to the array
}

}
closedir($dh);
}
}
?>

jfreak53
10-22-2004, 11:23 PM
Thank for the help...Just one problem, I don't think I specified myself the right way the first time, sorry my fault, I was in a hurry to leave, I had to go do something, so now I will exand on what I need exactly, what I need is a page like that, that I can call from a browser window let's say and call it with parameters like this, this is an example "displayimage.php?pid=1" or 2 or 3 depending on how many pics I have and somewhere in the file have a list of pics with their respective numbers, and further down have the HTML code for the page that will be displayed in the browser.

trib4lmaniac
10-23-2004, 12:24 AM
What about "displayimage.php?src=picture.jpg"? You could make that easily by expanding on the above code.

jfreak53
10-23-2004, 12:41 AM
that would work too...but the only problem is I don't want the users to see the image name...that's the thing...by the way where would I add my HTML Code in the code above?

marek_mar
10-23-2004, 12:55 AM
Um they will be able to find your image name even if you do it with numbers (in the HTML source). There are other ways of securing images.

jfreak53
10-23-2004, 06:04 PM
Ok, well where would I add my HTML Code for the page...I need to add full header info since I have some JavaScript in the page?

marek_mar
10-23-2004, 09:32 PM
Above the <?php and below the ?> tag.

jfreak53
10-25-2004, 06:52 PM
Ok, first I would like to thank you guys for all your help, second I'm sorry to be such a pain but need some more help guys. Ok I uploaded my page to the site, and this is the code of the page "one.php":



<html>
<head>
<title>Pics</title>
</head>

<script type="text/javascript" src="scripts.js"></script>

<script language="JavaScript" type="text/JavaScript">
adjust_popup();
</script>

<body>
<?php
// This is the directory in which the images reside.
$dir = "/done/im/";

// Open a known directory, and proceed to read its contents
if (is_dir($dir)) {
if ($dh = opendir($dir)) {
while (($file = readdir($dir)) !== false) {
if( preg_match('/^\.(bmp|jpe?g|gif|png)$/i', $extension) ) { // check the file is an image
echo $dir . $filename; // if it is, add it to the array
}

}
closedir($dh);
}
}
?>
</body>
</html>


That's the code, now it's under the directory done/im with the pics the same dir, which I have it entered there, this is from the root dir, when I run it without any commands nothing, when I try commands like "one.php?src=1.jpg" nothing, I've also tried "filename", "file" nothing it will not pull up the images, the images are named 1.jpg and 2.jpg, what do I have to add to this to get it work this way, please help?

trib4lmaniac
10-26-2004, 01:18 AM
I'm not sure if the path to the image directory has to be from the very root. In which case it would be a bit different (but I can't tell you what because it's your server). If you can make it a relative path you could try that, or find out the absolute path.

Also the line
echo $dir . $filename; // if it is, add it to the array is not actually affecting an array.
Change it to something like
$img_array[] = $dir . $filename; You may have to initalise it first. (With "$img_array = array();")
Then don't for get to echo the src that you want.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum