2012-07-06 131 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()}); 
} 

問題已關閉。