PHP File upload

1 st create html form to input the file to upload.The form need an enctype tag which specifies how form-data should be encoded before sending it to the server.Here we use “multipart/form-data” .That is no characters are encoded. This value is required when you are using forms that have a file upload control.

{code codetype=html}
<form action=”upload.php” enctype=”multipart/form-data” method=”POST”>

<input name=”MAX_FILE_SIZE” type=”hidden” value=”622000″ />

Upload this file: <input name=”userfile” type=”file” />

<input type=”submit” value=”Upload” />

</form> {/code}

Then create the php file upload script
{code codetype=php}
<?php
$uploaddir = ‘/upload/’;
$uploadfile = $uploaddir . basename($_FILES['userfile']['name']);

echo “<p>”;
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
echo “File uploaded successfully .\n”;
} else {
echo “Upload failed”;
}
?>
{/code}
The upload directory should have appropriate permissions to upload the file.

VN:F [1.9.17_1161]
Rating: 0.0/10 (0 votes cast)
VN:F [1.9.17_1161]
Rating: 0 (from 0 votes)

Related Posts

  • No Related Post
Related Posts with Thumbnails

About the Author

CoreTimer

has written 31 stories on this site.

System administrator(Linux/UNIX/Windows) RHCE,MCP,CCNA

Write a Comment

Copyright © 2012 CoreTimer.com|System Admin’s Reference. All rights reserved.

Switch to our mobile site