How to dynamicly create hyperlinks too all files in a directory?

I am building a site in which a user will upload file (excel spreadsheet, we'll call it report.xls), the file may then be downloaded and updated by another user and then re-uploaded. I want all versions of the file saved and avaible for download. I have create a MySql databse table with the following fields: "ID", "time", "uploader", and "filename". My question is 2 part: How do I create an upload script that will rename report.xls dynamicly so all versions can be saved to the same directory(we'll call the dir "ReportFiles").  Part 2: How do I create a page that will dynamicly list all files in "ReportFiles" dir, each with a hyperlink to the file?
dannyg280Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

dr_dedoCommented:
the upload part
rest is on the way
<?php
$suffix= date('Ymd');
if(isset($_FILES['file'])){
	$ext = strtolower(substr($_FILES['file']['name'],strrpos($_FILES['file']['name'],'.')));
	if ($ext == ".xls"){
		$target = $target . basename( $_FILES['file']['name']).$suffix;
		move_uploaded_file($_FILES['file']['tmp_name'], $target);
	}
}
?>
<form name="form" action="upload.php" method="POST" enctype="multipart/form-data">
<input type="file" name="file">
<input type="submit">
</form>

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
dr_dedoCommented:
part II

<?php
$path = 'uploads';
    $dir = opendir($path);
    while (($filename = readdir($dir))) {
     if (preg_match('/^.*?\.pdf$/i', $filename))
        echo "<a href='$path/$filename'>$filename</a></br>\n";
    }
    closedir($dir);
?>

Open in new window

0
dannyg280Author Commented:
Thank you for the quick responce. I am very much a beginner with PHP... I'm a little confused on the first part. Where is the upload dir defined?
0
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

dr_dedoCommented:
$target is where you could do that, this script uploads files in the same directory as the php file is
you can add any place as your upload folder e.g. folder called uploads. but make sure that this folder is created and you have write permission to it
$target = 'uploads/' . basename( $_FILES['file']['name']).$suffix;
0
dannyg280Author Commented:
Thanks again for your help!
0
dr_dedoCommented:
why did you give me B grade ??
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.