<form method="post" enctype="multipart/form-data"> File: <input type="file" name="file" value=30000/> <input type="submit" name="submit" value="submit"/> </form>The enctype lets the browser know of the encryption type.
The value =30000 means that the max file size can be 30kb.
Over to the PHP part.
At this stage, the file will already be stored on a temporary location, the details of which can
be obtained using the $_FILES array
The tmp_name is the temporary name of the file.
Now all we have to do is move the temporary file to our destination
We will use the move_uploaded_file function in PHP for this
<?php
if(isset($_POST['submit']))
{
$target='uploads/';
$tmp_name=$_FILES['file']['tmp_name'];
$file_name=$_FILES['file']['name'];
move_uploaded_file($tmp_name, $target.$file_name);
}
?>
It can be easily checked if the uploaded file is an image using the function getimagesize(). Just see if it is empty.If it is, then its not an image. getimagesize() can also be useful to determine the size of the image uploaded.
No comments:
Post a Comment