Open GoogleCodeExporter opened 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
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
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
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
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
thnaks :)
Original comment by boksi...@gmail.com
on 3 Feb 2011 at 12:06
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
Original issue reported on code.google.com by
boksi...@gmail.com
on 23 Jan 2011 at 7:42