Jump to content

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


bizerk

Recommended Posts

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:

[code]<?

$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>";
}
}

?>[/code]

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!?
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.