發送,當我在做一拖通過閱讀一堆教程式的上傳腳本,但他們只覆蓋JavaScript部分,我有對PHP的一部分問題。如何保存圖像服務器端JavaScript中
我上傳的圖像,因爲這:
$('#drop-zone').bind('drop', drop);
function drop(e) {
e.stopPropagation();
e.preventDefault();
e.dataTransfer = e.originalEvent.dataTransfer;
traverseFiles(e.dataTransfer.files);
}
traverseFiles使foreach循環每個文件並調用上傳funcion,還有我這樣做:
xhr = new XMLHttpRequest();
//some event listners for processing, on load
xhr.open("post", "core/plugins/upload/upload.class.php", true);
xhr.setRequestHeader("Content-Type", "multipart/form-data");
xhr.setRequestHeader("X-File-Name", file.name);
xhr.setRequestHeader("X-File-Size", file.size);
xhr.setRequestHeader("X-File-Type", file.type);
xhr.send(file);
然後在PHP中,我發現使用這將得到我原始數據的圖像
$file = file_get_contents('php://input');
編輯:找到解決方案
$fh = fopen($savedir, 'w') or die("can't open file");
fwrite($fh, $file);
fclose($fh);
順便說一下,$ _ POST和$ _FILES都是空的,當我用這個 – MakuraYami 2012-03-20 11:33:22