Jump to content


Photo

Reading A Directory, Opening the directory and than displaying the images.


  • Please log in to reply
No replies to this topic

#1 bizerk

bizerk
  • Members
  • PipPipPip
  • Advanced Member
  • 40 posts

Posted 01 October 2006 - 10:13 PM

Alright here is the dealio. I am trying to read a directory where all files are stored whenever a user uploads a file. The upload function is currently scripted in a file named "upload.php", and all the variable names and file extensions are defined in uploads.php as well. What i did was i created a whole new file and called it "allimages.php". At first i had it the file like this:

<?

$file_dir="users/public";

$dir=opendir($file_dir);
	while ($file=readdir($dir))
	{
		if ($file != "." && $file != "..")
		{
			echo "<a href=".$file_dir."/".$file." target=_blank>".$file."</a>";
			echo "<br>";
		}
	}

?>

what that code would do was Display the File names with a Link that had no extensions at the end so it would read it as a 404 no directory or file. For example: if i uploaded a picture called joe.jpg, my upload.php script would rename the file into the directory: "/users/public/joe.jpg" But this script would make links saying: "/users/public/joe". So than i decided I would do what i did with my upload.php script and just use the include() statement so i could obtain all the variables and values defined in "upload.php" My code now looks like this:

<?
include("upload.php");
$file_dir="users/public";
$split_ext = explode(',', $globalvars->settings['allowed_ext']);
$split_img = explode('.', $_FILES[$whichfile]['name']);
$extcount = count($split_ext);

$dir=opendir($file_dir);
while ($file=readdir($dir))
{
if ($file != "." && $file != "..")
{
echo "<a href=".$file_dir."/". $split_img[0] . "." . strtolower($split_img[1])." click here to view</a>";
echo "<br>";
}
}

?>

Alright well globalvars is reffering to the Admin settings that admins can change and the split_img is splitting it up into the "name" and the "extension". This should work since i did a A href link in upload.php that looked exactly like this that worked. But when i go to allimages.php the page is jusst blank. It does not have any errors or anything it just is blank. My reasoning for this would be that i did not include("upload.php") correctly or am not understanding what to do wit h"upload.php" if i need to put my whole "upload.php" script up here i will do so, but can anyone help me!?




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users