Solved

PHP upload and list updater program

Posted on 2007-11-13
3
182 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
Comment Utility
<?


$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
Comment Utility
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
Comment Utility
$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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
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 look for a specific file type in a local or remote server directory using PHP.
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…

744 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now