我使用的是laravel框架5.2。我已經成功實施了dropzone,並且我還完成了上傳圖像。現在的問題是,當我想從文件夾中刪除圖像,它給了我錯誤。我認爲我的代碼不適合刪除圖片。如何使用dropzone從文件夾中刪除圖像?
這裏是我的外接上傳圖片功能我已經在會話中上傳的圖片: -
public function addContributorimages(Request $request){
if($request->ajax()){
$image=$_FILES['file'];
if(!empty($image)){
if($image['error']==0){
$name = pathinfo($_FILES['file']['name']);
$ext = $name['extension'];
$rand=str_random(24).'.'.$ext;
$destination = base_path() . '/public/images/ContributorImages/';
if(is_uploaded_file($image['tmp_name'])){
list($width, $height, $source_type) = getimagesize($image['tmp_name']);
if ($width >= 10 && $height >= 10){
move_uploaded_file($image['tmp_name'],$destination.$rand);
$request->session()->put('contributorimage.'.str_random(5).'.image',$rand);
$images = $request->session()->get('contributorimage');
echo "<pre>"; print_r($images);
}
else{
echo "Error";die;
}
}
}
}
}
}
這是我的圖片 在這裏的附加功能是我的懸浮窗代碼: -
Dropzone.autoDiscover = false;
var fileList = new Array;
var i =0;
$("#my-awesome-dropzone").dropzone({
method:'POST',
maxFiles: 10,
paramName: "file",
maxFilesize: 10,
addRemoveLinks: true,
acceptedFiles: ".jpeg,.jpg,.png,.gif",
clickable: true,
init: function() {
// Hack: Add the dropzone class to the element
$(this.element).addClass("dropzone");
this.on("sending",function(file, xhr, formData) {
formData.append("_token", "{{ csrf_token() }}");
});
this.on("success", function(file, serverFileName) {
fileList[i] = {"serverFileName" : serverFileName, "fileName" : file.name,"fileId" : i };
//console.log(fileList);
i++;
});
this.on("removedfile", function(file) {
var rmvFile = "";
for(f=0;f<fileList.length;f++){
if(fileList[f].fileName == file.name)
{
rmvFile = fileList[f].serverFileName;
if (rmvFile){
$.ajax({
type: 'POST',
url: '../contributor/delete-subimages/'+rmvFile,
});
}
}
}
});
},
url: '../contributor/add-subimages',
});
});
我的圖片成功上傳,但我想從會議以及從文件夾中刪除圖像任何人都可以幫助我如何做到這一點 這裏是我的圖像刪除功能: -
public function deleteContributorImage(Request $request,$name = null){
$imageName=explode('.',$name);
$imageRandomName = $request->session()->get('contributorimage.'.$imageName[0].'.image');
$destination = base_path() . '/public/images/ContributorImages/';
if(unlink($destination.$imageRandomName)){
$request->session()->forget('contributorimage.'.$imageName[0]);
echo "success";
}
else{
echo "failed";
}
}
現在,當我上載圖片它創建這個sesssion現在我有在會議
Array
(
[Dkf08] => Array
(
[image] => whywu3dprVPKKkhUgdIMAdLQ.jpg
)
[rH5NV] => Array
(
[image] => i2sZEqjMdiQHcKRyy5Km9vlu.jpg
)
)
兩個圖像任何人都可以HLEP我如何解決售後服務這個問題。在此先感謝:)
**當我想從文件夾中刪除圖像,它給了我錯誤**它給出了什麼錯誤? –
ContributorController.php中的ErrorException行286:取消鏈接(G:\ xampp \ htdocs \ bantu/public/images/ContributorImages /):權限被拒絕 – kunal
權限被拒絕錯誤發生是因爲您嘗試刪除文件時沒有足夠的權限這樣做的權限。 –