2014-10-18 171 views
0


我需要知道如何刪除上傳的圖像或刪除輸入隱藏的值。例如,if(document.getElementByID(「eliminar」)。click())。 非常感謝。在圖像上刪除圖像上傳

<script type="text/javascript" > 
$(function(){ 
    var btnUpload=$('#upload'); 
    var status=$('#status'); 
    new AjaxUpload(btnUpload, { 
     action: 'upload-file.php', 
     name: 'uploadfile', 
     nSubmit: function(file, ext){ 
      if(!(ext && /^(jpg|png|jpeg|gif)$/.test(ext))){ 
       // extension is not allowed 
       status.text('Only JPG, PNG or GIF files are allowed'); 
       return false; 
      } 
      //status.text('Uploading...'); 
      status.show(); 
     }, 
     onComplete: function(file, response){ 
      //On completion clear the status 
      status.text(''); 
      //Add uploaded file to list 
      if(response==="success"){ 
       $('<li></li>').appendTo('#files').html('<img src="./uploads/'+file+'"/><input type="hidden" name="uploadfile[]" value="'+file+'"><button name="eliminar" id="eliminar">Eliminar</button>').addClass('success'); 
       if(document.getElementById("eliminar").click()){ 

       } 
      } else{ 
       $('<li></li>').appendTo('#files').text(file).addClass('error'); 
      } 
     } 
    }); 
}); 
</script> 

這是我上傳的-file.php

<?php 
$uploaddir = './uploads/'; 
$file = $uploaddir . basename($_FILES['uploadfile']['name']); 

if (move_uploaded_file($_FILES['uploadfile']['tmp_name'], $file)) { 
    echo "success"; 
} else { 
    echo "error"; 
} 
?> 

回答

1

unlink用於刪除文件在服務器上的PHP

unlink("./uploads/filename"); 

發送Ajax請求,並斷開鏈接的文件

function removeFile(){ 

$.ajax({ 
    url:'fileDel.php', 
    data:'fllename', 
    dataType:'json', 
    success:function(){ 
     alert("file deleted"); 
    } 
}); 
} 
+0

謝謝,但很抱歉,我怎麼能發送這個與Ajax? – juliangorge 2014-10-18 18:37:37