K
K
Konstantin Malyarov2017-03-11 01:14:44
PHP
Konstantin Malyarov, 2017-03-11 01:14:44

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

On the PHP server side :
<?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);
}

And $fileName returns. That is, the error is only in move_uploaded_file or $output_dir .

EasyPHP installed on Win10 1607 15048.0, run as admin. Where is the mistake?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question