如何修复:localhost中的文件上载错误?

u4dcyp6a  于 2021-06-21  发布在  Mysql
关注(0)|答案(1)|浏览(257)

这是我用来上传视频到我的网站的代码的一部分,代码在我的服务器上运行得很好,但在localhost(xampp)中,它总是返回错误语句而不上传视频,这是解析上传的代码

<?php

$file = (isset($_FILES["image"]) ? $_FILES["image"] : 0);

if (!$file) { // if file not chosen
    die("ERROR: Please browse for a file before clicking the upload button");
}
if($file["error"]) {

echo '<script>';
  echo 'console.log('. json_encode( $file["error"] ) .')';
  echo '</script>';
    die("ERROR: File couldn't be processed");

}
        $path = $_FILES['image']['name'];
        $ext = pathinfo($path, PATHINFO_EXTENSION);
        $tmp_file = $_FILES['image']['tmp_name'];
        $fileName = $_FILES['image']['name'];
        $fileName = preg_replace("/[^a-zA-Z0-9.]/", "", $fileName);
        $thumb = explode('.', $fileName);
        $thumbname = $thumb[0];
        $thumbname = $thumbname . ".jpg";
        $file_path = "images/video/" . $fileName;
        $imagename = "category_" . time() . "." . $ext;
        move_uploaded_file($tmp_file, $file_path)
?>

这是上传视频的功能代码,是post请求

function uploadFile() {
  var file = _("image").files[0];
   //alert(file.name+" | "+file.size+" | "+file.type);
  var formdata = new FormData();
  formdata.append("image", file);
  var ajax = new XMLHttpRequest();
  ajax.upload.addEventListener("progress", progressHandler, false);
  ajax.addEventListener("load", completeHandler, false);
  ajax.addEventListener("error", errorHandler, false);
  ajax.addEventListener("abort", abortHandler, false);
  ajax.open("POST", "file_upload_parser.php"); // http://www.developphp.com/video/JavaScript/File-Upload-Progress-Bar-Meter-Tutorial-Ajax-PHP
  //use file_upload_parser.php from above url
  ajax.send(formdata);
}

这是错误消息

console.log(1)ERROR: File couldn't be processed

我的php版本是7.2.8

m0rkklqb

m0rkklqb1#

你检查过你的房间了吗 upload_max_filesize directive in php.ini ? . 抱歉,我无法添加评论
并将此添加到检查部分之后和故障条件内部

print_r($_FILES["image"]["error"]);

告诉我们结果。

相关问题