简体   繁体   中英

How to fix :File Upload error in localhost?

this is a part of code I am using to upload video to my website, the code is running perfectly on my server but in localhost (xampp) it always returns the error statement and doesn't upload the video, this is the code for parsing the upload

<?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)
?>

and this is the code of function to upload video and it is POST request

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);
}

this is the error message

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

my php versionis 7.2.8

Have you check your upload_max_filesize directive in php.ini ? . sorry i can't add a comment

and add this after the checking part and inside the failed condition

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

and show us the result of it .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM