Very basic file upload information
By: Daniel
Here is a very basic code that will help you find all the information about a file being uploaded.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=windows-1250"> <title>Very Basic file upload info</title> </head> <body> <form action="echo $_SERVER['PHP_SELF']; " method="POST" enctype="multipart/form-data"> <input type="file" name="uFile"> <input type="submit" value="upload"> </form> if($_FILES) { $ext = explode('.',$_FILES['uFile']['name']); $extension = count($ext) - 1; echo 'Type: '.$_FILES['uFile']['type'].'<br>'; echo 'Name: '.$_FILES['uFile']['name'].'<br>'; echo 'tmp_name: '.$_FILES['uFile']['tmp_name'].'<br>'; echo 'Size: '.$_FILES['uFile']['size'].'<br>'; echo 'Extension: '.$ext[$extension].'<br>'; move_uploaded_file($_FILES['uFile']['tmp_name'], "/path/to/uploads/".$_FILES['uFile']['name']); } </body> </html>
The main key to this code is in the form. You MUST include the:
enctype="multipart/form-data"
The next key part is the input type. You must have an input type as file instead of text.
Then you can just use the $_FILES variable to get all the information you need.
Make sure that you change the “/path/to/uploads/” in the move_uploaded_file() line to the path of where the file will be uploaded to.
If you forget what information you can get from the $_FILES variable just do a print_r($_FILES) and you can see everything.
Hope you enjoy.





















January 16th, 2007 at 3:31 pm
This is a great blog!
January 28th, 2007 at 8:55 pm
Hi,
I found your blog via google by accident and have to admit that youve a really interesting blog
Just saved your feed in my reader, have a nice day