SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Sep 2012
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Looking for some help with a script.

    Hi all,

    Unfortunately i lost a good friend recently to a injury he aquired during battle in afganistan as we were both disabled veterans and met while taking computer classes together. As he was much much farther into the courses, he had written me a easy "upload file" script for the back end of a site i was working on. Unfortunately he was unable to complete a portion that i threw at him right before he passed.

    With this code it is just your basic "upload a file code" to be download by others. What i was looking to have added was once the file was uploaded by admin it would show on the front end near the download button a date ( 9/27/12) of the last upload. Also show on the back end the same date of when the last upload was done. Im not to sure on how hard it would be as myself are at the beginning stages of my courses but he mentioned that he was just taken refresher courses.

    So here is my code let me know if there are any questions:

    PHP Code:
    [SIZE=4][COLOR="#FF0000"]<?php



    $number_of_uploads 
    6;

    # Set allowed file types, lowercase without period (.)

    $allowed_file_types =     array("viv","csv","zip","txt");

    # Change the upload_folder path, with trailing slash, 
    # to your full directory path if neccessary, and set 
    # permissions (chmod) to 777.

    $upload_folder "uploads/";

    # Set maximum file upload size in kilobytes.

    $max_size_in_kb 2000;

    # Set 1 to rename files, 0 to keep original file names.

    $rename_files 0;

    # END SETTING VARIABLES #################

    ?>

    <div id='main-left'><div id=''><img src="../images/header-trade.jpg" alt="" /></div><br/>

    <!--The start of the Admin upload Function-->

    <br/>
    <div class='news-left2' >



    <table width="640px">
        <tr>
            <td width="213px"><img src="images/downloads.png" alt="" /></td>
            <td width=""><?php

    function printForm()
    {
    global 
    $allowed_file_types,$number_of_uploads;



    print 
    "<form action=\""$_SERVER["PHP_SELF"] ."\" method=\"post\" enctype=\"multipart/form-data\">\n<p>";

        for(
    $i=0;$i<$number_of_uploads;$i++)
        {
        print 
    "<input type=\"file\" name=\"file[]\" /><br />";
        }

    print 
    "<input type=\"hidden\" name=\"upload\" value=\"1\">\n";
    print 
    "<input type=\"submit\" value=\"Upload\"/></p>\n</form>\n";
    }

    $fileNAMES = array();

    if(isset(
    $_POST['upload']))
    {
        for(
    $i=0;$i<$number_of_uploads;$i++)
        {
            if(
    strlen($_FILES['file']['name'][$i]) > 0)
            {
            
    $ext end(explode("."$_FILES['file']['name'][$i]));

                if(
    $rename_files == 1)
                {
                
    $fileNAMES[$i] = time()+rand(0,999999);
                }
                else
                {
                
    $xperiods str_replace("." $ext""$_FILES['file']['name'][$i]);
                
    $fileNAMES[$i] = str_replace("."""$xperiods);
                }

                if(!
    in_array(strtolower($ext), $allowed_file_types))
                {
                print 
    "<p>FAILED: "$_FILES['file']['name'][$i] ." ERROR: File type not allowed.</p>\n";
                }
                elseif(
    $_FILES['file']['size'][$i] > ($max_size_in_kb*1024))
                {
                print 
    "<p>FAILED: "$_FILES['file']['name'][$i] ." ERROR: File size to large.</p>\n";
                }
                elseif(
    file_exists($upload_folder.$fileNAMES[$i] ."."$ext))
                {
                print 
    "<p>FAILED: "$fileNAMES[$i] ."."$ext ." ERROR: File already exists.</p>\n";
                }
                else
                {
                    if(
    move_uploaded_file($_FILES['file']['tmp_name'][$i], $upload_folder.$fileNAMES[$i] ."."$ext))
                    {
                    print 
    "<p>UPLOADED: "$fileNAMES[$i] ."."$ext ."</p>\n";
                    }
                    else
                    {
                    print 
    "<p>FAILED: "$_FILES['file']['name'][$i] ." ERROR: Undetermined.</p>\n";
                    }
                }
            }
        }

    printForm();
    }
    else
    {
    printForm();
    }

    ?>[/COLOR][/SIZE]

    Thank you for all your help and God Bless you and the USA!!!

  2. #2
    SitePoint Member
    Join Date
    Sep 2012
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I cant believe no one could possibly help me here. This site was given to me as a very helpful site. Anyone? Please, help a disabled vet... I would be very thankful. '

    Thanks in advance

  3. #3
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,394
    Mentioned
    147 Post(s)
    Tagged
    4 Thread(s)
    Take a look at http://php.net/manual/en/function.stat.php
    Quote Originally Posted by sayoung View Post
    I cant believe no one could possibly help me here.
    Sometimes questions get answered within a couple of minutes, sometimes it takes longer, sometimes the answer never comes. It depends on the question, on the time of day/year, on how much time people have at the moment to look at your problem. We all do this voluntarily you know?
    So please refrain from bumping your own post after only 9 hours.

  4. #4
    SitePoint Member
    Join Date
    Sep 2012
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I guess i didn't think about that. My apologizes to all.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •