2012-05-18 32 views
1

我有一個Web編程的問題,我需要處理的是以下:上傳被取消時如何識別文件字符串?

「你的表單元素傳遞給startImageUpload()功能,並試圖將其存儲作爲HTML添加到imagef1_cancel element字符串。這是行不通的,你需要給每個表格一個unique id,並用這個字符串來標識需要取消的上傳。「

目前,當點擊取消按鈕時,它無法識別想要從行中刪除的文件。下面是什麼var_dump($GET)print($imagecancelsql)被示出:

說明:未定義指數:imagecancelname在/xxx/Mobile_app/cancelimage.php上線22 陣列(0){} DELETE FROM圖片WHERE鏡像文件= '的圖像文件中/'

那麼如何解決這個問題,以便它可以識別需要取消上傳的文件字符串?

下面是試圖解決這個我目前的嘗試:

var sourceImageForm; 

     function startImageUpload(imageuploadform, imagecancelname){ 

    $(imageuploadform).find('.imagef1_upload_process').css('visibility','visible'); 
    $(imageuploadform).find('.imagef1_cancel').css('visibility','visible'); 
    $(imageuploadform).find('.imagef1_upload_form').css('visibility','hidden'); 
    sourceImageForm = imageuploadform; 

/*The above would show and hide elements within the form the file is being uploaded. 
For example if I have three forms and the second form is uploading a file, then it 
shows and hides the elements within the second form only */ 

     $(imageuploadform).find('.imagef1_cancel').html('<div><button type="button" class="imageCancel" id="image_cancel_' + imagecancelname + '">Cancel</button></div>').find(".imageCancel").on("click", function(event) { 
     $.ajax("cancelimage.php?imagecancelname=" + $(this).attr('id').slice(13)); 

});  
     return true; 
} 

下面是表單代碼:

var $fileImage = $("<form action='imageupload.php' method='post' enctype='multipart/form-data' target='upload_target' onsubmit='return startImageUpload(this);' class='imageuploadform' >" + 
    "Image File: <input name='fileImage' type='file' class='fileImage' /></label><br/><br/><label class='imagelbl'>" + 
    "<input type='submit' name='submitImageBtn' class='sbtnimage' value='Upload' /></label>" +  
    "</p><p class='imagef1_cancel' align='center'></p>" + 
    "<iframe class='upload_target' name='upload_target' src='#' style='width:0;height:0;border:0px;solid;#fff;'></iframe></form>"); 

最後下面是它是假設刪除分貝cancelimage.php行包含文件名:

<?php 

     // ... connected to DB 

$image_cancel = ''; 
if (isset($_GET["imagecancelname"])) { $image_cancel = $_GET["imagecancelname"]; } 

     $image_cancel = $_GET["imagecancelname"]; 
     $imagecancelsql = " 
     DELETE FROM Image 
     WHERE ImageFile = 'ImageFiles/".mysql_real_escape_string($image_cancel)."' 
     "; 

     print $imagecancelsql; 

     mysql_close(); 

    ?> 

回答

1
Notice: Undefined index: imagecancelname 

你可以擺脫這個通知,因爲這GET指數的生存確認時:

$image_cancel = ''; 
if (isset($_GET["imagecancelname"])) { $image_cancel = $_GET["imagecancelname"]; } 


// This line is only asking what that underscore is good for (typo?) 
// $image_cancel_ = $_GET["imagecancelname"]; 
       ^
       | 
       ? ? ? 

後來你只能繼續,如果$ image_cancel設置爲有用的東西,並允許(從不信任用戶(!)輸入並做適當的驗證)。

+0

嗨,它給了我相同的通知,我上面更新了代碼,顯示了當前代碼現在看起來像什麼 – user1394925

+0

是的,因爲你仍然留下這一行:$ image_cancel = $ _GET [「imagecancelname」];在你的代碼中(沒有isset()的行) – djot

+0

哦,是的,我是個傻瓜。乾杯:) – user1394925