Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

PHP upload and list updater program

Posted on 2007-11-13
3
Medium Priority
?
189 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

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…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to dynamically set the form action using jQuery.
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…

715 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