Reputation: 1437
okay, i have a form dropdown
<select name="select_category" id="select_category">
<option value="cheese-cakes">Cheesecakes</option>
<option value="fruit-cakes">Fruitcakes</option>
</select>
and a hidden text input
<input type="hidden" id="category_container" />
in my 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'
});
I want to pass the value of the text box #category_container as post data and send it to uploadify.php, so that the filename that would be saved is the value of the textbox/data passed.
The problem is that, there's a file that's been uploaded but there's no filename. example: it only uploads '.png' , '.jpg' files
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.';
}
Upvotes: 2
Views: 1434
Reputation: 1437
This code was missing.
'onUploadStart':function(file){
$('#file_upload').uploadify('settings','formData',{'cat_name' : $('#category_image_name').val()});
}
question closed.
Upvotes: 2