Page 1 of 1

file uploads with php

Posted: Mon Jun 14, 2004 7:00 pm
by snpo123
I know this is a pretty basic question, but I havent ever had to use file uploads. What is the basic syntax to upload a file from a php page? Do you need a special type of html form? And how to I tell php where to store the file? Thanks.

Posted: Mon Jun 14, 2004 7:02 pm
by markl999

Posted: Mon Jun 14, 2004 7:07 pm
by kettle_drum
Yes. you first need to make a form like so:

Code: Select all

<form method="POST" action="" name="file_upload" enctype="multipart/form-data">
            File: <input type="file" name="upload" size="25">
            <input type="submit" name="submit" value="Upload">
         </form>
Notice the enctype="multipart/form-data" in the form tag.

Then when you submit the form the file will be uploaded to a tmp directory and the details are held in $_FILES.

In this case $_FILES['upload'] will hold an array of values to do with the file. Its called 'upload' as the form field is called this.

Do a print_r($_FILES['upload']) to see what values you have access to - which are tmp_name, size, type, name etc.

Check out my file upload class in the code snippet section to learn more, its fairly simple when youve got the basics. Just pratice.