2014-05-13 65 views
0

我使用jqueryForm和imgAreaSelect插件上傳圖像,使用imgAreaSelect插件裁剪,然後保存。問題是我不知道如何獲得上傳後的文件名。當然,我知道它是如何製作的,知道源代碼,但不能從上傳的PHP腳本訪問變量。ajax上傳後獲取文件名

$(document).ready(function() { 
     $(".uploadform").ajaxForm({ 
      target: '#viewimage', 
      beforeSubmit: function() { 
       $("#viewimage").html('Uploading...'); 
      }, 
      success: function() { 

       $('img').imgAreaSelect({ 
       aspectRatio: '166:90', 
       minHeight: 90, 
       minWidth: 166, 
       onSelectEnd: function (img, selection) { 
        $('input[name="x1"]').val(selection.x1); 
        $('input[name="y1"]').val(selection.y1); 
        $('input[name="x2"]').val(selection.x2); 
        $('input[name="y2"]').val(selection.y2);    
        $('input[name="width"]').val(selection.x2-selection.x1); 
        $('input[name="height"]').val(selection.y2-selection.y1);  
        $('input[name="source"]').val($(this));      
       }}); 

      } 
     }); 
    }); 

所以問題是我如何從腳本使用ajax訪問源圖像上傳變量?

UPD: PHP腳本:

$imagename = md5(uniqid().time()).".".$extension; 
     $tmp = $_FILES['imagefile']['tmp_name']; 
     if (move_uploaded_file($tmp, $filepath . $imagename)) { 
     echo '<img class="preview" alt="" src="'.$filepath.'/'. 
     $imagename .'" />'; 
+1

請張貼的PHP腳本。你應該能夠在你的php腳本的$ _FILES []變量中找到任何文件。 – ksealey

+0

在主帖中發佈了php腳本。 – Bullwinkle

回答

0

名稱將在

$_FILES['imagefile']['name'] 
+0

不,這樣的變量中沒有名稱。 – Bullwinkle

+0

林相當肯定會有如果輸入的名稱是'imagefile'並且它已上傳。這是來自W3。 http://www.w3schools.com/php/php_file_upload.asp – ksealey

0

嗯,這是東西,幫我

$(document).ready(function() { 
    $(".uploadform").ajaxForm({ 
     target: '#viewimage', 
     beforeSubmit: function() { 
      $("#viewimage").html('Uploading...'); 
//   showRequest;    
     }, 
     success: function() { 
     $('img').imgAreaSelect({ 
//   showResponse(); 
      aspectRatio: '166:90', 
      minHeight: 90, 
      minWidth: 166, 
      onSelectEnd: function (img, selection) { 
       $('input[name="x1"]').val(selection.x1); 
       $('input[name="y1"]').val(selection.y1); 
       $('input[name="x2"]').val(selection.x2); 
       $('input[name="y2"]').val(selection.y2);    
       $('input[name="width"]').val(selection.x2-selection.x1); 
       $('input[name="height"]').val(selection.y2-selection.y1);  
       $('input[name="source"]').val($('img').attr('src')); 
      }}); 

     } 
    }); 
});