2014-05-13 68 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')); 
      }}); 

     } 
    }); 
});