mercredi 31 août 2016

File upload 302?

I've finally gotten my asynchronous file upload working, except it only seems to handle text files.

If I upload a text file, it works and saves the file. If I upload an image, it fails firebug reports the response has a 302 status, and I get sent to the root directory of my public_html

I thought it may be related to file size, but doesn't seem to be the case, as I made the text file larger than the image, and it worked out.

I'm not sure where to start troubleshooting, I'll place the PHP relevant snippet below.

PHP

$fn = (isset($_SERVER['HTTP_X_FILENAME']) ? $_SERVER['HTTP_X_FILENAME']:false);
echo $fn;

try{
    file_put_contents("upload/".$fn, file_get_contents("php://input"));
    //echo file_get_contents("upload/".$fn);
}catch(exception $e){
    echo $e->getMessage();
}

JS

function UploadFile(file){
    var xhr = new XMLHttpRequest();
    //on the below if
    //xhr.upload: returns a XMLHttpRequestUpload Object, I believe just to check if it's supported in broswer
    if (xhr.upload){
        xhr.open("POST","http://ift.tt/2bBkJsv",true);
        xhr.setRequestHeader("X-FILENAME",file.name);

        xhr.onreadystatechange = function(){
        if(xhr.status == 200 && xhr.readyState == 4){
            callback(xhr.responseText);
        }
    }
    xhr.send(file);
    }else{
        alert("Sorry, don't think this is supported in your browser.");
    }
}

Is there a request header I should be setting? Is it something in php.ini I need to change? My max post size is I think 32MB, not sure what else would effect this.




Aucun commentaire:

Enregistrer un commentaire