我有一个带有图片上传功能的添加产品页面。 此代码段位于我的视图文件中。
<div class="well">
<?php if ($modelProductitem->imagepath != '') { ?>
<div class="row oc-img-exist">
<div class="col-xs-6 col-md-4 oc-thumbs col-xs-offset-4" data-product-id="<?php echo $modelProductitem->productid; ?>">
<a href="#4" class="oc-remove-icon"><i class="fa fa-close text-danger"></i></a>
<a href="#4" class="thumbnail">
<img src="<?php echo Octopus::getImagePathProductsWeb ().'/'.$productId.'/'.$modelProductitem->imagepath; ?>" title="<?php echo $modelProductitem->imagepath; ?>">
</a>
</div>
</div>
<?php } ?>
<div class="col-md-12 drop-file dropzone oc-dropzone-previews dropzone-responsive">
x
</div>
<div class="clearfix"></div>
</div>
在我的JS中
productDropzone = new Dropzone ('#frm-add-product', {
url: '<?php echo Yii::app()->getBaseUrl (true); ?>/product/uploadProductImage',
acceptedFiles: '.png, .PNG, .jpeg, .JPEG, .jpg, .JPG',
autoProcessQueue: false,
addRemoveLinks: true,
uploadMultiple: true,
previewsContainer: '.oc-dropzone-previews',
clickable: '.drop-file',
init: function() {
this.on ('complete', function (file) {
if (productDropzone.getUploadingFiles ().length === 0 && productDropzone.getQueuedFiles ().length === 0) {
}
});
}
});
在我的ProductController中,我有这个功能: -
public function actionUploadProductImage () {
echo "test"; print_r($_POST);
die();
}
然而,点击提交后,dropzone js上没有错误。该页面像往常一样被重定向,好像它根本没有通过“actionUploadProductImage”。
有人可以帮忙吗?谢谢
答案 0 :(得分:0)
The image files are getting from $_FILES but you are using $_POST
public function actionUploadProductImage () {
$ds = DIRECTORY_SEPARATOR; //1
$storeFolder = 'uploads'; //2
if (!empty($_FILES)) {
$tempFile = $_FILES['file']['tmp_name']; //3
$targetPath = dirname( __FILE__ ) . $ds. $storeFolder . $ds; //4
$targetFile = $targetPath. $_FILES['file']['name']; //5
move_uploaded_file($tempFile,$targetFile); //6
}
}