Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

PHP upload and list updater program

Posted on 2007-11-13
3
Medium Priority
?
191 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 2000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
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

926 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