2012-07-06 132 views
2

好吧,我有一个表格下拉将数据传递给uploadify

<select name="select_category" id="select_category"> 
<option value="cheese-cakes">Cheesecakes</option> 
<option value="fruit-cakes">Fruitcakes</option> 
</select> 

和一个隐藏的文本输入

<input type="hidden" id="category_container" /> 

在我的jQuery/JavaScript的

$('#select_category').change(function(){ 
var cat = $('#select_category option:selected').attr('value'); 
$('#category_container').attr('value',cat); 
}); 

uploadify

var plug = '<?php echo plugins_url('plugin_name') ?>'; 
$('#file_upload').uploadify({ 
'formData' : {'cat_name' : $('#category_container').attr('value')}, 
swf'  : plug + '/uploadify/uploadify.swf', 
'uploader' : plug + '/uploadify/uploadify.php' 
}); 

我想将文本框#category_container的值作为发布数据传递并发送到uploadify.php,以便保存的文件名是传递的文本框/数据的值。

问题是,上传了一个文件,但没有文件名。例如:只上传 '巴纽',名为.jpg文件

uploadify.php

$name = $_GET['cat_name']; 

$tempFile = $_FILES['Filedata']['tmp_name']; 
$targetPath = $targetFolder; 
$targetFile = rtrim($targetPath,'/') . '/' . $_FILES['Filedata']['name']; 

$path = pathinfo($targetFile); 

$newTargetFile = $targetFolder.$name.'.'.$path['extension']; 

// Validate the file type 
$fileTypes = array('jpg','jpeg','gif','png'); // File extensions 
$fileParts = pathinfo($_FILES['Filedata']['name']); 

if (in_array($fileParts['extension'],$fileTypes)) { 
    move_uploaded_file($tempFile,$newTargetFile); 
    echo $newTargetFile; 
} else { 
    echo 'Invalid file type.'; 
} 

回答

2

此代码失踪。

'onUploadStart':function(file){ 
    $('#file_upload').uploadify('settings','formData',{'cat_name' : $('#category_image_name').val()}); 
} 

问题已关闭。