I have a problem while I need to send data using uploadify script.
For first time, uploadify script is installed correctly, everything works fine. But I need to use uploaded data (via uploadify script) for mysql and others.
Here is my code for calling uploadify script:
<script type="text/javascript">
$(document).ready(function() {
$('#file_upload').uploadify({
'uploader' : '/uplod/uploadify/uploadify.swf',
'script' : '/uplod/uploadify/uploadify.php',
'cancelImg' : '/uplod/uploadify/cancel.png',
'folder' : '/uplod/uploads/',
'auto' : true,
'multi' : false,
'onComplete': function(event, queueID, fileObj, response, data){
var form = document.forms['form'];
var i = 0;
var el = document.createElement("input");
el.type = "hidden";
el.name = "test";
el.id = "test2";
el.value = fileObj.name;
form.appendChild(el); },
'onAllComplete': function(event,data) { document.getElementById('form').submit();},
});
});
</script>
I found this code at: http://www.uploadify.com/forums/discussion/7102/for-all-those-who-struggle-on-inserting-filenames-into-a-db-after-uploading/p1
It`s about how to callback after file is uploaded.
Here is uploadify.php code:
<?php
if (!empty($_FILES)) {
$tempFile = $_FILES['Filedata']['tmp_name'];
$targetPath = $_SERVER['DOCUMENT_ROOT'] . $_REQUEST['folder'] . '/';
$targetFile = str_replace('//','/',$targetPath) . $_FILES['Filedata']['name'];
move_uploaded_file($tempFile,$targetFile);
echo '0'; // Required to trigger onComplete function on Mac OSX (same for linux and windows as it seems)
}
else { // Required to trigger onComplete function on Mac OSX (same for linux and windows as it seems)
echo '1';
$video = $_POST[test];
$textfield = $_POST[textfield];
echo $video;
echo $textfield;
}
?>
And here is form which I need to create how I be able to getting this work.
<form id="form" name="form" method="post" enctype="multipart/form-data" action="uploadify/uploadify.php">
<input id="file_upload" name="file_upload" type="file" />
<input type="text" name="textfield" id="textfield" />
</form>
Problem is here, when I use enctype="multipart/form-data" uploadify.php writes to me 0, when I delete enctype="multipart/form-data" writes to me 1. And that`s what I need. As you can see from code, I put some stupid code at end of uploadify.php to test it.
I think this don’t work because in javascript code, I don’t write anywhere enctype. maybe I wrong.
I tried editing this:
var form = document.forms['form'].enctype = "multipart/form-data";
but nothing,
also I tried:
'onAllComplete': function(event,data) { document.getElementById('form').enctype;
document.getElementById('form').submit();},
but again nothing. All help is welcome…
P.S This is test example, for this code I don’t need multipart/form-data but on project which testing, I need multipart/form-data because I`m testing uploadify script for small video uploader, and I need a cover picture for each video.
Try:
instead of
But as you don’t use multi-uploads, I dont see any need to do this in 2 steps(first send the file, then the complete form).
See the scriptData-option, it allows you to send both, the file and additional data: