PHP file uploader

Here is a simple working php uploader. Save the code under the name of upload.php and use it:
<form enctype="multipart/form-data" method="post" action="<?echo $_SERVER['PHP_SELF'];?>">
<label for="file">File:</label>
<input id="file type="file" name="fileupl" size="50" maxlength="100000" />
<input name="submfile" type="submit" id="submfile" value="Upload >" />
<input type="hidden" name="step2" value="true" />
</form>

<? 
ini_set("upload_max_filesize", "100M");//set the max. file upload size
$directory=""; //$directory is the default upload dir

$target_path = $directory."/";
if ($handle = opendir($target_path)) {
echo "Published files:\n";
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") { $arr_files=1; echo "<br /><a href=\"/$target_path$file\">$file</a>";  }
}
closedir($handle);
}
if (empty($arr_files)) $arr_files="There are no uploaded files.";
else if($step2 == 'true')
{
ini_set("max_execution_time", "500"); //maximum upload execution time
if (!is_dir($target_path)) {mkdir($directory, 0700);}
$target_path = $target_path . basename( $_FILES['fileupl']['name']);
if(move_uploaded_file($_FILES['fileupl']['tmp_name'], $target_path)) {
echo "The file ".basename( $_FILES['fileupl']['name'])." has been uploaded successfuly.";
}
}
?>
by Nevyan Neykov



0 коментара:

Post a Comment