【发布时间】:2012-01-28 07:03:47
【问题描述】:
我有一个表格
<form id="profile_imageform" class="image_form" enctype="multipart/form-data">
<fieldset>
<div class="entry">
<label>Filename:</label>
<input type="file" name="file" id="file" />
</div>
</fieldset>
<div class="actions">
<button type="submit">Save & Close</button>( <a href="#/profile" class="cancel">Cancel</a> )
</div>
</form>
我的 js 文件看起来像
ProfileForm.prototype.init = function(){ var self = this;
//Initialize properties
this.view = $( "#profile_form_view" );
this.imageForm = $( "#profile_imageform" );
this.fields.id = this.imageForm.find( ":input[ name = 'id' ]" );
this.fields.image = this.imageForm.find( ":input[ name = 'file' ]" );
//Bind the submit handler
this.imageForm.submit(function( event ){
//Submit the form
self.saveImage(this.fields.id.val(), this.fields.image.val());
//Cancel default event
return( false );
});
ProfileForm.prototype.saveImage = function( id, image, onSuccess, onError ){
var self = this;
application.ajax({
url: "test.php",
data: {
method: "saveImage",
id: id,
image: image
},
success: function( response ){
if (response.success){
onSuccess( response.data );
}else{
onError( response.errors );
}
}
});
};
但是
this.fields.image.val()
返回我需要的图像名称是 tmp_name。 是否有可能在 jQuery 中获得它的 tmp_name ?如果有怎么办?
但是这个 php 代码也返回错误
if (isset($_POST['method']))
{
if (isset($_POST['image']))
{
echo $_FILES['image']['tmp_name'];
}
}
【问题讨论】: