我使用Dropzone JS和從我的前端(localhost:9000),我打電話upload.php我得到的圖像,然後將其上傳到後端(localhost:80 )在一個文件夾中。 這裏是我的html:Dropzone JS無法上傳文件
<form action="localhost:80/ProgettoTimelinegit/api/upload.php" class="dropzone" id="my-dropzone" enctype="multipart/form-data">
</form>
我的javascript:
Dropzone.autoDiscover = false;
$("#my-dropzone").options = {
maxFilesize: 4, // MB
url:"http://localhost:80/ProgettoTimelinegit/api/upload.php",
addRemoveLinks : true,
uploadMultiple:true,
paramName:"file",
parallelUploads: 2,
maxFiles: 10,
autoProcessQueue: true,
headers: {
// remove Cache-Control and X-Requested-With
// to be sent along with the request
'Cache-Control': null,
'X-Requested-With': null
}
};
和upload.php的
$ds = DIRECTORY_SEPARATOR; //1
$storeFolder = '/xampp/htdocs/images/'; //2
if(!empty($_FILES)) {
// START // CREATE DESTINATION FOLDER
define('DESTINATION_FOLDER','../api/upload/');
if ([email protected]_exists(DESTINATION_FOLDER)) {
if (!mkdir(DESTINATION_FOLDER, 0777, true)) {
$errors[] = "Destination folder does not exist or no permissions to see it.";
}
// END // CREATE DESTINATION FOLDER
$temp = $_FILES['file[]']['tmp_name'];
$dir_seperator = "fold/";
//$destination_path = dirname(__FILE__).$dir_seperator.$folder.$dir_seperator;
$destination_path = DESTINATION_FOLDER.$dir_seperator;
$target_path = $destination_path.(rand(10000, 99999)."_".$_FILES['file']['name']);
move_uploaded_file($temp, $target_path);
}
}
如果我上傳的圖片,在控制檯(對於每一個瀏覽器) it
POST localhost:80/ProgettoTimelinegit/api/upload.php net::ERR_UNKNOWN_URL_SCHEME
我想要做的是在本地主機加載圖片:80/progettoTimelinegit/API /上傳/
我從HTTPS使用教程:// WWW .startutorial.com /篇/圖/如何到內建一個文件上傳 - 成型 - 使用 - dropzonejs及PHP – Fedeco