Would Like Some Ideas on How to Go About This...

Discussion in 'Programming' started by Analyst101, Apr 4, 2012.

to remove all ads.
  1. Analyst101

    Analyst101 New Member

    Hello Everyone,

    I was hoping you all would be so kind and help layout some steps for me in a little project I am undertaking.

    Basically I want a secretary to be able to upload a file (pdf document) after that file is uploaded I want it to automatically create a link to the file on our website. This will be used to make my job easier as I won't have to go in and add HTML code every week when a new board meeting agenda is published along with the minutes.

    Could you guys please offer me some advice on how to go about this? It would be a great help. Thank you! :)
  2. leroy30

    leroy30 New Member

    Hi Analytst101,

    A local web developer should be able to implement this solution for you in under a day's work.

    Otherwise I suggest Google!

    Le-roy Staines
  3. Analyst101

    Analyst101 New Member

    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">
    <title><!-- Insert your title here --></title>
    <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" />


    and the corresponding php file looks like this (NOTE this code is only for handling the upload process for PDF documents):


    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:

    if ($handle = opendir('Invoices/')) {
    while (false !== ($file = readdir($handle))) {
    if ($file != "." && $file != "..") {
    echo "<a href=\"Invoices/".$file."\">".$file."</a><br />";

    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!
  4. MarkR

    MarkR New Member

    Look up: http://www.php.net/manual/en/function.array-multisort.php

    Failing that look up quick sort and bubble sort algorithms.

    You also need to make sure that you check the files you are accepting in the upload only have one file extension. For example test.php.pdf will be accepted and can be read as either a PHP or pdf file.
  5. GaryWright

    GaryWright New Member

    Which platform or language are you using for creating your website?
  6. Analyst101

    Analyst101 New Member

    The site is built in php

Share This Page