有我的代码:
$('#file_upload').uploadify({
'swf' : 'uploadify.swf',
'uploader' : 'uploadify.php',
'onSelect' : function(file) {
$('#start').removeClass('hidden');
},
'method' : 'post',
'formData' : {
'to': $('input#to').val(),
'from': $('input#from').val(),
'subject': $('input#subject').val()
},
'onQueueComplete' : function(queueData) {
window.location.replace("index.php?success=uploaded");
},
'onUploadSuccess' : function(file, data, response) {
alert('The file ' + file.name + ' was successfully uploaded with a response of ' + response + ':' + data);
}
// Your options here
});
如您所见,我通过 POST 方法发送三个参数 TO、FROM、SUBJECT。
有服务器脚本
if (!empty($_FILES)) {
$tempFile = $_FILES['Filedata']['tmp_name'];
$targetPath = $_SERVER['DOCUMENT_ROOT'] . $targetFolder;
$targetFile = rtrim($targetPath,'/') . '/' . $_FILES['Filedata']['name'];
// Validate the file type
$fileTypes = array('jpg','jpeg','gif','png'); // File extensions
$fileParts = pathinfo($_FILES['Filedata']['name']);
if (move_uploaded_file($tempFile, $targetFile)) {
echo $_REQUEST['subject'];
} else {
echo "Something wrong";
}
}
并回显 $_REQUEST['subject']; 什么都不返回 我的错误在哪里?
例如,如果我将 'subject': $('input#subject').val() 更改为 'subject': 'test subject' 就可以了。但我需要从输入中发送一个值。我该怎么做?
多谢