嗨,这里是新手,非常感谢您的帮助。我从在线教程中借用了这个,并尝试根据我的需要进行定制。
这个工作文件,但输出消息打印在另一个页面/屏幕上。只是我需要的 id 验证消息将打印在同一页面/屏幕上而无需重定向。我尝试$location
从函数中删除,但似乎并没有帮助我。如何使所有验证消息出现在MSGPane
?
谢谢您的帮助。
这是代码;
<?php
$directory_self = str_replace(basename($_SERVER['PHP_SELF']), '', $_SERVER['PHP_SELF']);
if(isset($_POST['submit']))
{
$directory_self = str_replace(basename($_SERVER['PHP_SELF']), '', $_SERVER['PHP_SELF']);
$uploadsDirectory = $_SERVER['DOCUMENT_ROOT'] . $directory_self . 'uploaded_files/';
$uploadForm = 'http://' . $_SERVER['HTTP_HOST'] . $directory_self . 'index.php';
$uploadSuccess = 'http://' . $_SERVER['HTTP_HOST'] . $directory_self . $_SERVER['PHP_SELF'];
$fieldname = 'file';
$errors = array(1 => 'php.ini max file size exceeded',
2 => 'html form max file size exceeded',
3 => 'file upload was only partial',
4 => 'no file was attached');
isset($_POST['submit'])
or error('the upload form is neaded', $uploadForm);
($_FILES[$fieldname]['error'] == 0)
or error($errors[$_FILES[$fieldname]['error']], $uploadForm);
@is_uploaded_file($_FILES[$fieldname]['tmp_name'])
or error('not an HTTP upload', $uploadForm);
@getimagesize($_FILES[$fieldname]['tmp_name'])
or error('only image uploads are allowed', $uploadForm);
$now = time();
while(file_exists($uploadFilename = $uploadsDirectory.$now.'-'.$_FILES[$fieldname]['name']))
{
$now++;
}
@move_uploaded_file($_FILES[$fieldname]['tmp_name'], $uploadFilename)
or error('receiving directory insuffiecient permission', $uploadForm);
header('Location: ' . $uploadSuccess);
}
function error($error, $location, $seconds = 5)
{
header("Refresh: $seconds; URL=\"$location\"");
echo "
<div id='Upload'>\n\n
<h1>Upload failure</h1><br>
<p>An error has occured:
<span class='red'>. $error .</span><br>
The upload form is reloading</p>
</div>";
exit;
}
$max_file_size = 3500000; // size in bytes
?>
<!doctype html>
<html>
<head><title></title></head>
<body>
<table>
<tr>
<td class='MSGPane'></td>
</tr>
</table>
</html>