file uploads with php
Moderator: General Moderators
file uploads with php
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.
-
kettle_drum
- DevNet Resident
- Posts: 1150
- Joined: Sun Jul 20, 2003 9:25 pm
- Location: West Yorkshire, England
Yes. you first need to make a form like so:
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.
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>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.