我从文件上传中得到一个错误,我只有一个文件输入,我得到错误
发生错误。请与管理员联系。
我的代码:
//html your text <input type="file" name="the_file[]" multiple >
//php $currentDirectory = getcwd();
$uploadDirectory = "/uploads/";
$fileExtensionsAllowed = ['image/png, image/jpeg']; // These will be
the only file extensions allowed
$fileName = $_FILES['the_file[]']['name'];
$fileSize = $_FILES['the_file[]']['size'];
$fileTmpName = $_FILES['the_file[]']['tmp_name[]'];
$fileName = $prenume . $nume . $fileName . ".png";
$fileExtension = strtolower(end(explode('.',$fileName)));
$uploadPath = $currentDirectory . $uploadDirectory . $fileName;
if(isset($_POST['submit'])){
//upload fisiere
if ( in_array($fileExtension,$fileExtensionsAllowed)) {
$errors[] = "This file extension is not allowed. Please upload a JPEG or PNG file";
}
if ($fileSize > 400000000000) {
$errors[] = "File exceeds maximum size (4MB)";
}
if (empty($errors)) {
$didUpload = move_uploaded_file($fileTmpName, $uploadPath);
if ($didUpload) {
echo "Upload-ul fisierului " . $fileName . " s-a efectuat cu succes <br>";
} else {
echo "An error occurred. Please contact the administrator.";
}
} else {
foreach ($errors as $error) {
echo $error . "These are the errors" . "\n";
}
}
我期望得到多个文件上传,如果我上传一个文件它的工作,它可能是因为名称或某事
2条答案
按热度按时间h79rfbju1#
显然问题出在这句台词上:第一个月
它应该是:
$fileTmpName = $_FILES['the_file']['tmp_name'];
还应将文件名更新为:
$fileName = $prenume . $nume . $fileName;
最后,您应该处理用户选择多个文件进行上传的情况,您可以通过循环
$_FILES
数组来完成此操作:kq0g1dla2#
最终代码: