【发布时间】:2016-11-14 10:15:46
【问题描述】:
我正在使用 Dropzone JS,并从我的前端 (localhost:9000) 调用 upload.php,在其中获取图像,然后将其上传到后端 (localhost:80) 的文件夹中。 这是我的 html:
<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
}
};
并上传.php
$ds = DIRECTORY_SEPARATOR; //1
$storeFolder = '/xampp/htdocs/images/'; //2
if(!empty($_FILES)) {
// START // CREATE DESTINATION FOLDER
define('DESTINATION_FOLDER','../api/upload/');
if (!@file_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);
}
}
如果我在控制台中上传图片(适用于每个浏览器) 它
POST localhost:80/ProgettoTimelinegit/api/upload.php net::ERR_UNKNOWN_URL_SCHEME
我要做的是在 localhost:80/progettoTimelinegit/api/upload/ 中加载图片
【问题讨论】:
标签: javascript php image-uploading dropzone.js