cybermatatu / dnd-file-upload

Automatically exported from code.google.com/p/dnd-file-upload
0 stars 0 forks source link

Where is upload.php file #5

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Hello,

where i can fine the upload.php file

Original issue reported on code.google.com by boksi...@gmail.com on 23 Jan 2011 at 7:42

GoogleCodeExporter commented 9 years ago
Am I right this is the way I can react in upload.php (and this can in fact be 
upload.php?)

<?php
print_r($_FILES);
print_r($_POST);
?>

Original comment by novor...@gmail.com on 3 Feb 2011 at 12:12

GoogleCodeExporter commented 9 years ago
Hi,

those arrays are both empty in windows environment. They are working on LAMP 

Original comment by boksi...@gmail.com on 3 Feb 2011 at 7:58

GoogleCodeExporter commented 9 years ago
This approach did not work, bad guesswork. It's empty on LAMP as well.

Original comment by novor...@gmail.com on 3 Feb 2011 at 10:09

GoogleCodeExporter commented 9 years ago
This is the part in JavaScript that does the sending. I guess need to dig into 
PHP manuals to figure how to process it on server side.

var xhr = new XMLHttpRequest();
var upload = xhr.upload;
xhr.open(opts.method, opts.url);
xhr.setRequestHeader("Cache-Control", "no-cache");
xhr.setRequestHeader("X-Requested-With", "XMLHttpRequest");
xhr.setRequestHeader("X-File-Name", file.fileName);
xhr.setRequestHeader("X-File-Size", file.fileSize);
xhr.setRequestHeader("Content-Type", "multipart/form-data");
xhr.send(file);

Original comment by novor...@gmail.com on 3 Feb 2011 at 10:11

GoogleCodeExporter commented 9 years ago
SOLUTION upload.php:
-----------------------------
<?php

class Uploader
{
    private $fileName;
    private $contentLength;
    private $path;
    private $log;

    public function __construct($uploads)
    {
        $this->path=$uploads;
        $log=fopen($this->path . 'log.txt','w');
        if (array_key_exists('HTTP_X_FILE_NAME', $_SERVER) && array_key_exists('CONTENT_LENGTH', $_SERVER)) {
            $this->fileName = $_SERVER['HTTP_X_FILE_NAME'];
            fwrite($log,"Receiving '" .  $this->fileName . "'\n");
            $this->contentLength = $_SERVER['CONTENT_LENGTH'];
        } else throw new Exception("Error retrieving headers");
    }

    public function receive()
    {
        if (!$this->contentLength > 0) {
            throw new Exception('No file uploaded!');
        }

        file_put_contents(
            $this->path . $this->fileName,
            file_get_contents("php://input")
        );

        fclose($log);
        return true;
    }
}

$uploads="upload/";
try {
    $ft = new Uploader($uploads);
    $ft->receive();
} catch (Exception $e) {
    $fd=fopen($uploads . 'err.txt','w');
    fwrite($fd,'Caught exception: ' .  $e->getMessage() . "\n");
    fclose($fd);
}
fclose($log);
?>

Thanks for great job overall,
Novorado

Original comment by novor...@gmail.com on 3 Feb 2011 at 12:00

GoogleCodeExporter commented 9 years ago
thnaks :)

Original comment by boksi...@gmail.com on 3 Feb 2011 at 12:06

GoogleCodeExporter commented 9 years ago
Hi,

I am trying this with LAMP, but the _SERVER array does not contain the 
HTTP_X_FILE_XXX keys. CONTENT_LENGTH is set though. I tried with chrome and 
firefox.

Any idea about this ?

Original comment by jdefa...@gmail.com on 20 Mar 2013 at 8:24