PostSava’s Single File Upload Script

Single file upload script. All the variables can be easily changed to suit your needs: – maximum file size that can be uploaded – allowed file extensions of files that are uploaded Easy to integrate into any design as it is very easy to remove it’s css and use your own. You can also view a list of the uploaded files. Single click file delete


I rewrote the code so that the notices Commander Killbot asked me about no longer appear.

No Demo | Download (2.35KB) ( 20731 downloads )

Stay Connected

Subscribe to RSS Feed

Subscribe to RSS Feed

Follow me on Twitter

Follow me on Twitter

Subscribe via e-mail

Subscribe via e-mail

Comments 13 Responses to “Sava’s Single File Upload Script”

  1. Looks good, was just wondering how safe this was to use. Is it safe enough to allow visitors to use it without worrying about the safety of my site?

  2. Very nice! 😀

    I need to upload a directory, can u help me in some way?

  3. Hi, that’s me again.

    i need to put upload.php inside directory (root/dir)

    i dont know php, i try this at line 22
    $url_dir = “http://”.$_SERVER[‘HTTP_HOST’].”/DIRR”.dirname($_SERVER[‘PHP_SELF’]);
    but it says “change permission to 777 failed.” when i click on UPLOAD.

    Hope u can help me

  4. Fabio, you have to chmod to 777 the directory in which you try to upload.
    For example you want to upload into directory “files” then you have to create “/root/files” directory and chmod it to 777.

  5. Hi,
    Thanks for the script – I’m using it with XAMPP on a SuSE box and it seems to be working for both uploads and deletes, but I’m getting error notices like this:

    Notice: Use of undefined constant del – assumed ‘del’ in /opt/lampp/htdocs/upload/upload.php on line 42

    Notice: Undefined index: del in /opt/lampp/htdocs/upload/upload.php on line 42

    Notice: Undefined index: userfile in /opt/lampp/htdocs/upload/upload.php on line 54

    Notice: Undefined index: userfile in /opt/lampp/htdocs/upload/upload.php on line 76

    Notice: Use of undefined constant message – assumed ‘message’ in /opt/lampp/htdocs/upload/upload.php on line 131
    deleted successfully

    Since the script is working, this is not of vital importance, but can you help me figure out what’s going on with the notices?


  6. Commander Killbot. I forgot to reply to your comment. The script has been rewritten. The notices will not appear if you download the new archive.

  7. When a user uploads the same file name it overwrites the original file. I need it to rename the new file instead.

    1. Locate this line in upload.php:
      $file_name = str_replace(“‘”,””,$file_name);
      and add these 2 lines right after it:

      $new_file_name = explode(‘.’, $file_name);
      $file_name = $new_file_name[0].date(‘YmdHis’).’.’.$new_file_name[1];

      This way no uploaded file will ever have the same name.

  8. I grabbed your script and I get this back:

    Warning: opendir( [function.opendir]: failed to open dir: No such file or directory in /home/.peggy/gsmanga/ on line 96

    Warning: readdir(): supplied argument is not a valid Directory resource in /home/.peggy/gsmanga/ on line 101

    Any help? I do have that directory and I did CHmod it to 777 like it said in your instructions. I am trying to allow people to upload music files for an online jukebox for my site…

    1. Email sent.

  9. Hi!

    Clicking on View (Action -> View file) gives me the following url:\/files/testupload.txt

    Why is there a \ in the url?

    1. Not sure. If you made any modifications download the script again.

      This is the code that generated that link:

      $url_dir = "http://".$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']);
      $upload_url = $url_dir."/files/";

      No \ there

  10. Hi, 2 questions:

    a) $upload_url = $url_dir.”/uploads/”; should be a ## User edited variables ## ?

    b) i can’t remove files