?
Solved

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

Posted on 2008-02-11
6
Medium Priority
?
565 Views
Last Modified: 2013-12-12
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?
0
Comment
Question by:dannyg280
  • 4
  • 2
6 Comments
 
LVL 16

Accepted Solution

by:
dr_dedo earned 750 total points
ID: 20866652
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
 
LVL 16

Assisted Solution

by:dr_dedo
dr_dedo earned 750 total points
ID: 20866773
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
 

Author Comment

by:dannyg280
ID: 20867347
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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
LVL 16

Assisted Solution

by:dr_dedo
dr_dedo earned 750 total points
ID: 20867520
$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
 

Author Closing Comment

by:dannyg280
ID: 31429797
Thanks again for your help!
0
 
LVL 16

Expert Comment

by:dr_dedo
ID: 20867714
why did you give me B grade ??
0

Featured Post

[Webinar] Kill tickets & tabs using PowerShell

Are you tired of cycling through the same browser tabs everyday to close the same repetitive tickets? In this webinar JumpCloud will show how you can leverage RESTful APIs to build your own PowerShell modules to kill tickets & tabs using the PowerShell command Invoke-RestMethod.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
It’s a season to be thankful, and we’re thankful for users like you who engage on site, solve technology problems, and network with others in the industry. What tech are we most thankful for? Keep reading.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

601 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question