There are two basic things covered here. The form that will be used to post the file data to and the actual program that does the uploading. Further we will discuss the method that PHP itself suggests for uploading files. Process 1 HTML PART
<form enctype="multipart/form-data" action="__URL__" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="30000" />
Upload a file: <input name="smefile" type="file" />
<input type="submit" value="Upload" />
</form>
Note the enctype is set to "multipart/form-data". This is crucial to the working of the application. If it is not specified here then the program will not work. Next you'll notice that MAX_FILE_SIZE precedes the file input field. The MAX_FILE_SIZE for this demonstration is limited to 30000 bytes, or about 29K, but can easily be modified for larger files. Finally you have the input sections. The first is set to create an input box that allows the user to choose his file and the second is the button that actually submits the file for upload. In the next section you'll notice that the name of the input element for type="file" will be used to determine the name to pull from the $_FILES array. Form Method must be POST Process 2 PHP PART
<form enctype="multipart/form-data" action="__URL__" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="30000" />
Upload a file: <input name="smefile" type="file" />
<input type="submit" value="Upload" />
</form>
Note the enctype is set to "multipart/form-data". This is crucial to the working of the application. If it is not specified here then the program will not work. Next you'll notice that MAX_FILE_SIZE precedes the file input field. The MAX_FILE_SIZE for this demonstration is limited to 30000 bytes, or about 29K, but can easily be modified for larger files. Finally you have the input sections. The first is set to create an input box that allows the user to choose his file and the second is the button that actually submits the file for upload. In the next section you'll notice that the name of the input element for type="file" will be used to determine the name to pull from the $_FILES array. Form Method must be POST Process 2 PHP PART
<?php
$imgdir = '/imgdir/';$uploadfile = $imgdir. basename($_FILES['smefile']['name']);
if (move_uploaded_file($_FILES[ 'smefile']['tmp_name'], $uploadfile)) {
echo "File successfully uploaded";
} else {
echo "Upload failed";
}?>
No comments:
Post a Comment
Thank you for your Comment....