Members

Technology Zones

Articles

Hosted By

MaximumASP

Info

Rated
Read 79,997 times

Contents

Related Categories

Uploading files in PHP - Handling the upload

S.S. Ahmed

Handling the upload

You can check if the file has been uploaded to the server using different attributes provided by the PHP. For example, if you dont want to allow your users to upload the same file again and again, you can put a restriction on the user to upload new files only. We can set limit on the size of the file to be uploaded by adding an <input> element with the NAME attribute set to MAX_FILE_SIZE and the VALUE to the upper limit. I haven't demonstrated this in my sample code but here the piece of code for your reference:

<input type=hidden name=MAX_FILE_SIZE value=1024>
<imput type=file name=userfile>

Remember, the hidden <input> tag should precede the file <input> tag.

Place a check before displaying a message, use the empty() function to check if $userfile variable contains something or not, if its empty then display the message telling the user that the file hasn't been uploaded otherwise display the message that the file has been uploaded successfully. And that's it!

S.S. Ahmed is a senior IT Professional and works for a web and software development firm. Ahmed is a Microsoft Office SharePoint Server MVP. Ahmed specializes in creating database driven dynamic web sites. He has been working with SharePoint for the last 3-4 years. He develops customized SharePoint solutions. Ahmed likes to hop into other tools as well. Ahmed has used Project Server, InfoPath and BizTalk. Ahmed enjoys travelling and has been to many parts of the world. Web: www.walisystems.com Blog: www.sharepointblogs.com/ssa

Comments

  • Re: [2892] Uploading files in PHP

    Posted by CarlBe on 28 Sep 2006

    I am trying to allow people to upload image files and post them to me.


     


    I have copied your code exactly but get the following;


    Parse error: parse erro...

  • can the form change the filename as it is uploaded

    Posted by tpwalker1980 on 12 Jun 2005

    Is there anyway to change the filename as it is uploaded? So myhouse.jpg is auto changed to file1.jpg

    For instance, anytime a file is uploaded via the form... Have it name the file MYFILE.jp...

  • permission change of uploaded file

    Posted by lenilachica on 04 Feb 2005

    gud day!
    i have problems regarding the file i uploaded on the server.

    the file is pic.bmp

    i uploaded it in "subs/images"
    then i am about to create an exec statement to convert this logo.

    it...

  • change/set permissions on upload

    Posted by mike00 on 29 Jan 2005

    Hi,

    I'm relatively new to php. I'm using a code simliar to the one posted for file uploads. I was wondering if there was any way to set the permisson to "read only" upon upload. I've been having pr...

  • root address

    Posted by lenilachica on 28 Jan 2005

    how can i get the exact address of the uploaded file i browsed.

    like when i browsed it from "C:/picture.bmp"

    how can i get this address? i mean how could i get these exact words?

    and when ...