Solved

PHP upload and list updater program

Posted on 2007-11-13
3
185 Views
Last Modified: 2013-12-13
Hi,

Im a looking for some general (or specific) advice on how I can accomplish the following using php and mysql.

I want to give the user the ability to upload a pdf document to a file on the server. (I have this part figured out already using a php based upload form)

I want to have a web page that lists the pdfs that have been uploaded that directory in order by date 2007_01_12, 2006_06_04...ect

So I guess what I am wondering is how would I make it so the user simply uploads a document to the server. But, when the document gets uploaded, the php updates the web page that lists all the the documents in the upload directory listing a link to that newly uploaded document.

Is there a any to accomplish this without a database? Does anyone know where I could find some example code that does this?
0
Comment
Question by:jackie777
  • 2
3 Comments
 
LVL 20

Expert Comment

by:steelseth12
ID: 20277024
<?


$d = dir("directory_path");

while (false !== ($entry = $d->read())) {
   
   if($entry != "." && $entry !="..") {
   
         $time = filectime($d->path.DIRECTORY_SEPARATOR.$entry);
         $files[$time]["name"][] = $entry ;
         $files[$time]["path"][] = $d->path.DIRECTORY_SEPARATOR.$entry ;
      }
}

$d->close();

krsort($files);


      foreach($files as $value) {
      
            if(count($value["name"]) > 1) {
            
                  for($i=0;$i<count($value["name"]);$i++) {
                  
                        print "<a href='".$value["path"][$i]."'>".$value["name"][$i]."</a><br>";
                  
                  }
            
            
            }else{
      
                  print "<a href='".$value["path"][0]."'>".$value["name"][0]."</a><br>";
            }
      
      }
?>
0
 

Author Comment

by:jackie777
ID: 20277206
That worked perfectly, thanks.

Any idea what could do to limit the list that is displayed to 50? So that as new files are added, the old ones  no longer become available.
0
 
LVL 20

Accepted Solution

by:
steelseth12 earned 500 total points
ID: 20277251
$d = dir("directory_path");

$j=0;
while (false !== ($entry = $d->read())) {
   
   if($entry != "." && $entry !=".." && $j++ < 50) {
   
         $time = filectime($d->path.DIRECTORY_SEPARATOR.$entry);
         $files[$time]["name"][] = $entry ;
         $files[$time]["path"][] = $d->path.DIRECTORY_SEPARATOR.$entry ;
      }
}

$d->close();

krsort($files);


      foreach($files as $value) {
     
            if(count($value["name"]) > 1) {
           
                  for($i=0;$i<count($value["name"]);$i++) {
                 
                        print "<a href='".$value["path"][$i]."'>".$value["name"][$i]."</a><br>";
                 
                  }
           
           
            }else{
     
                  print "<a href='".$value["path"][0]."'>".$value["name"][0]."</a><br>";
            }
     
      }
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

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

Question has a verified solution.

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

Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
The viewer will learn how to count occurrences of each item in an array.
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…

789 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