Put this together...
Thank you for the advice Leroy!
Google has come to the rescue
so far this is what I have come up with:
I have a webform to upload files with the following code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title><!-- Insert your title here --></title>
</head>
<body>
<form enctype="multipart/form-data" action="upload.php" method="post">
<input type="hidden" name="MAX_FILE_SIZE" value="1000000" />
Choose a file to upload: <input name="uploaded_file" type="file" />
<input type="submit" value="Upload" />
</form>
</body>
</html>
and the corresponding php file looks like this (NOTE this code is only for handling the upload process for PDF documents):
<?php
if((!empty($_FILES["uploaded_file"])) && ($_FILES['uploaded_file']['error'] == 0)) {
//Check if the file is JPEG image and it's size is less than 350Kb
$filename = basename($_FILES['uploaded_file']['name']);
$ext = substr($filename, strrpos($filename, '.') + 1);
if (($ext == "pdf") && ($_FILES["uploaded_file"]["type"] == "application/pdf") &&
($_FILES["uploaded_file"]["size"] < 4550000)) {
//Determine the path to which we want to save this file
$newname = dirname(__FILE__).'www.csustan.edu/asi-usu/Invoices/'.$filename;
//Check if the file with the same name is already exists on the server
if (!file_exists($newname)) {
//Attempt to move the uploaded file to it's new place
if ((move_uploaded_file($_FILES['uploaded_file']['tmp_name'],$newname))) {
echo "It's done! The file has been saved as: ".$newname;
} else {
echo "Error: A problem occurred during file upload!";
}
} else {
echo "Error: File ".$_FILES["uploaded_file"]["name"]." already exists";
}
} else {
echo "Error: Only .pdf images are accepted for upload";
}
} else {
echo "Error: No file uploaded";
}
$varname = $_POST[$newname];
echo "<SCRIPT LANGUAGE='javascript'>refreshParent();</SCRIPT>";
?>
?>
once the pdf file is uploaded to the desired directory, the following php code, placed in a separate file will display the contents of the desired directory with clickable links to the files themselves:
<?php
if ($handle = opendir('Invoices/')) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
echo "<a href=\"Invoices/".$file."\">".$file."</a><br />";
}
}
closedir($handle);
}
?>
my new question is, is it possible to list the files in order based on something like the date uploaded? or in alphabetical order? Thanks for all your feedback!