Answer the question
In order to leave comments, you need to log in
EasyPHP, why doesn't file upload work?
There is a plugin for jQuery.
I installed it, everything works except one. Save to folder. From the HTML
page : jQuery
Script :
<div id="fileuploader">Upload</div>
$("#fileuploader").uploadFile({
url: "../php/foto_upload.php",
fileName: "myfile",
showProgress: true,
showPreview: true,
autoDone: true,
showDelete: true,
showDownload: true,
previewHeight: "15%",
previewWidth: "15%"
});
<?php
<?php
$output_dir = "../tmp/";
if (isset($_FILES["myfile"])) {
$ret = array();
//This is for custom errors;
// $custom_error = array();
// $custom_error['jquery_upload_file_error'] = "File already exists";
// echo json_encode($custom_error);
// die();
$error = $_FILES["myfile"]["error"];
//You need to handle both cases
//If Any browser does not support serializing of multiple files using FormData()
if (!is_array($_FILES["myfile"]["name"])) { //single file
$fileName = $_FILES["myfile"]["name"];
move_uploaded_file($_FILES["myfile"]["tmp_name"], $output_dir . $fileName);
$ret[] = $fileName;
} else { //Multiple files, file[]
$fileCount = count($_FILES["myfile"]["name"]);
for ($i = 0; $i < $fileCount; $i++) {
$fileName = $_FILES["myfile"]["name"][$i];
move_uploaded_file($_FILES["myfile"]["tmp_name"][$i], $output_dir . $fileName);
$ret[] = $fileName;
}
}
echo json_encode($ret);
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question