Monday, December 24, 2007

PHP File Upload : Boilerplate Basic Code

This is the most minimal code needed to upload files with a PHP script.

< source_code>

$uploaddir = '/home/lance/www/uploads/';
$http_post_uploaded_file = $_FILES['uploadedfile']['name']; 
$uploadfile = ${uploaddir}.${http_post_uploaded_file};
move_uploaded_file($_FILES['uploadedfile']['tmp_name'],
                   ${uploadfile}); 
$upload_url="/uploads/".${http_post_uploaded_file};
if ($_FILES['uploadedfile']['name']!="") {
echo "<href=\"".${upload_url}."\">here is what you uploaded</a>\n";   }

</source_code>

No comments: