I can not pass values to the uploadify scriptData - php

this is my code:
<script type="text/javascript">
$(function() {
$('#file_upload').uploadify({
'swf' : '../js/uploadify/uploadify.swf',
'uploader' : '../js/uploadify/uploadify.php',
'height' : '60',
'width' : '60',
'folder' : '../uploads/',
'muti' : true,
'displayData': 'speed',
'scriptData' : {'evento' : '<?php echo $galery['event'] ?>'},
});
});
I try to pass a value of a variable to the file uploadify.php where there will register these data in the database, but can not in any way ... I've tried looking at some papers but the result is the same ...

You can tray to create session_id() and pass to this value through by uploadify. Then call the session id from acton page. And match them.

Related

Using multiple uploadify button in one page

I have 4 uploadify button in my page. This s my codes :
$(function() {
$('#file_upload').uploadify({
'formData' : {
'PHPSESSID': '<?=session_id()?>',
'timestamp' : '<?php echo $timestamp;?>',
'token' : '<?php echo md5('unique_salt' . $timestamp);?>'
},
'swf' : 'uploadify.swf',
'uploader' : 'uploadify.php?id=<? echo $resID; ?>&state=<? echo strtolower($negeri); ?>',
'onQueueComplete': function() {
setTimeout(function(){location.reload(true);},100)
}
});
$('#file_upload1').uploadify({
'formData' : {
'PHPSESSID': '<?=session_id()?>',
'timestamp' : '<?php echo $timestamp;?>',
'token' : '<?php echo md5('unique_salt' . $timestamp);?>'
},
'swf' : 'uploadify.swf',
'uploader' : 'uploadify1.php?id=<? echo $resID; ?>&state=<? echo strtolower($negeri); ?>',
'onQueueComplete': function() {
setTimeout(function(){location.reload(true);},100)
}
});
$('#file_upload2').uploadify({
'formData' : {
'PHPSESSID': '<?=session_id()?>',
'timestamp' : '<?php echo $timestamp;?>',
'token' : '<?php echo md5('unique_salt' . $timestamp);?>'
},
'swf' : 'uploadify.swf',
'uploader' : 'uploadify2.php?id=<? echo $resID; ?>&state=<? echo strtolower($negeri); ?>',
'onQueueComplete': function() {
setTimeout(function(){location.reload(true);},100)
}
});
$('#file_upload3').uploadify({
'formData' : {
'PHPSESSID': '<?=session_id()?>',
'timestamp' : '<?php echo $timestamp;?>',
'token' : '<?php echo md5('unique_salt' . $timestamp);?>'
},
'swf' : 'uploadify.swf',
'uploader' : 'uploadify3.php?id=<? echo $resID; ?>&state=<? echo strtolower($negeri); ?>',
'onQueueComplete': function() {
setTimeout(function(){location.reload(true);},100)
}
});
});
The problem is it's destroying my SESSION data. When I delete 3 othe rscripts. It doesnt destroy my SESSION. So, I've decided to use one script to all the 4 uploadify button in the page. I tried doing this :
$('.file_upload').uploadify({
'formData' : {
'PHPSESSID': '<?=session_id()?>',
'timestamp' : '<?php echo $timestamp;?>',
'token' : '<?php echo md5('unique_salt' . $timestamp);?>'
},
'swf' : 'uploadify.swf',
'uploader' : 'uploadify.php?id=<? echo $resID; ?>&state=<? echo strtolower($negeri); ?>',
'onQueueComplete': function() {
setTimeout(function(){location.reload(true);},100)
}
});
Even this :
$(".file_upload").each(function() {
$(this).uploadify({
'formData' : {
'PHPSESSID': '<?=session_id()?>',
'timestamp' : '<?php echo $timestamp;?>',
'token' : '<?php echo md5('unique_salt' . $timestamp);?>'
},
'swf' : 'uploadify.swf',
'uploader' : 'uploadify.php?id=<? echo $resID; ?>&state=<? echo strtolower($negeri); ?>',
'onQueueComplete': function() {
setTimeout(function(){location.reload(true);},100)
}
});
});
But both of them doesn't work. The button does not appear.
Is there any way to solve it?
Thank you :D. Really appreciate your help
Are you tring this from official doc. I'm about:
formData : { '<?php echo session_name();?>' : '<?php echo session_id();?>' }
and in uploadify.php
$session_name = session_name();
if (!isset($_POST[$session_name])) {
exit;
} else {
session_id($_POST[$session_name]);
session_start();
}
$('.selectorClass').uploadify({
formData:{
PHPSESSID: '<?=session_id()?>',
timestamp: '<?php echo $timestamp;?>',
token : '<?php echo md5('unique_salt' . $timestamp);?>'
},
swf : 'uploadify.swf',
uploader : 'uploadify.php?id=<? echo $resID; ?>&state=<? echo strtolower($negeri); ?>',
onQueueComplete: function() {
setTimeout(function(){location.reload(true);},100)
}
});
after looking into the source code of uplodify i found that object passed to uplodify has keys without single quotes like this
var settings = $.extend({
// Required Settings
id : $this.attr('id'), // The ID of the DOM object
swf : 'uploadify.swf', // The path to the uploadify SWF file
uploader : 'uploadify.php', // The path to the server-side upload script
// Options
auto : true, // Automatically upload files when added to the queue
buttonClass : '', // A class name to add to the browse button DOM object
buttonCursor : 'hand', // The cursor to use with the browse button
buttonImage : null, // (String or null) The path to an image to use for the Flash browse button if not using CSS to style the button
buttonText : 'SELECT FILES', // The text to use for the browse button
checkExisting : false, // The path to a server-side script that checks for existing files on the server
debug : false, // Turn on swfUpload debugging mode
fileObjName : 'Filedata', // The name of the file object to use in your server-side script
fileSizeLimit : 0, // The maximum size of an uploadable file in KB (Accepts units B KB MB GB if string, 0 for no limit)
fileTypeDesc : 'All Files', // The description for file types in the browse dialog
fileTypeExts : '*.*', // Allowed extensions in the browse dialog (server-side validation should also be used)
height : 30, // The height of the browse button
method : 'post', // The method to use when sending files to the server-side upload script
multi : true, // Allow multiple file selection in the browse dialog
formData : {}, // An object with additional data to send to the server-side upload script with every file upload
preventCaching : true, // Adds a random value to the Flash URL to prevent caching of it (conflicts with existing parameters)
progressData : 'percentage', // ('percentage' or 'speed') Data to show in the queue item during a file upload
queueID : false, // The ID of the DOM object to use as a file queue (without the #)
queueSizeLimit : 999, // The maximum number of files that can be in the queue at one time
removeCompleted : true, // Remove queue items from the queue when they are done uploading
removeTimeout : 3, // The delay in seconds before removing a queue item if removeCompleted is set to true
requeueErrors : false, // Keep errored files in the queue and keep trying to upload them
successTimeout : 30, // The number of seconds to wait for Flash to detect the server's response after the file has finished uploading
uploadLimit : 0, // The maximum number of files you can upload
width : 120, // The width of the browse button
// Events
overrideEvents : [] // (Array) A list of default event handlers to skip
/*
onCancel // Triggered when a file is cancelled from the queue
onClearQueue // Triggered during the 'clear queue' method
onDestroy // Triggered when the uploadify object is destroyed
onDialogClose // Triggered when the browse dialog is closed
onDialogOpen // Triggered when the browse dialog is opened
onDisable // Triggered when the browse button gets disabled
onEnable // Triggered when the browse button gets enabled
onFallback // Triggered is Flash is not detected
onInit // Triggered when Uploadify is initialized
onQueueComplete // Triggered when all files in the queue have been uploaded
onSelectError // Triggered when an error occurs while selecting a file (file size, queue size limit, etc.)
onSelect // Triggered for each file that is selected
onSWFReady // Triggered when the SWF button is loaded
onUploadComplete // Triggered when a file upload completes (success or error)
onUploadError // Triggered when a file upload returns an error
onUploadSuccess // Triggered when a file is uploaded successfully
onUploadProgress // Triggered every time a file progress is updated
onUploadStart // Triggered immediately before a file upload starts
*/
}, options);
This could be the reason behind your problem, try this out, remove single quotes flanking json keys.

uploadify - show uploaded images on page

I'm building a site (in php) that uses uploadify to allow a user to upload portfolio images.
I have uploadify working fine, but I'm just wondering the best way of showing the uploaded images on the page once they have been uploaded. Is it possible to do without a page refresh?
I've pasted my uploadify code below:
<script>
<?php $timestamp = time();?>
var counter = 1;
$(function() {
$('#file_upload').uploadifive({
onUploadComplete: function(event, queueID, fileObj, reponse, data) {
//alert(counter);
counter = counter +1 ;
},
'buttonText' : 'Upload Images...',
'uploadLimit' : 12,
'uploadScript' : '/includes/uploadifive.php',
'checkScript' : '/includes/check-exists.php',
'auto' : true,
'method' : 'post',
formData : {
'page_id' : '<? echo $pageDetails->row['page_id'] ?>',
'counter' : counter,
'timestamp' : '<? echo $timestamp;?>',
'token' : '<? echo md5('unique_salt' . $timestamp);?>'
},
});
});
</script>
I'm not too sure how to get the file name from uploadify
Sure, you can just add img elements to the page dynamically via the DOM:
var img = document.createElement('img');
img.src = "/path/to/the/new/img.png";
document.getElementById("somecontainer").appendChild(img);
Live Example | Source
You may need to do an ajax call to the server to get the path of the new image, unless that falls out naturally from your application logic.
In the edition I use there is a function
onUploadSuccess : function(file,data,response){
}
Then I can get file name by file.name;
So in your code maybe the fileObj, You can try fileObj.name to get the name of the file you upload.

jQuery fancybox post

I have a jQuery fancybox that takes the content from an iframe, here's the link to popup the box:
<a class="action_btn recommend_btn" act="recommend" href="recommend.php">Recommend</a>
and here's the code for the fancybox:
$(".action_btn").not(".save").click(function() {
$.fancybox({
'width' : 560,
'height' : 530,
'autoScale' : false,
'transitionIn' : 'none',
'transitionOut' : 'none',
'type' : 'iframe',
'href' : $(this).attr('href')
});
return false;
});
now I would like to post something to this recommend.php, so I can use this attribute/value in recommend.php, how can I do this?
One way I can think of is to store a session in the page prior to hyperlinking, but doesn't seem right.. seems like there should be a better way to do this
You should still be able to use the _GET http variable I think so:
Click
Then in recommend.php use $_GET['some_variable']. Unless fancybox does something crazy with iFrames.
since you already are using jQuery and possibly want to do this on the fly use .post().
$(".action_btn").not(".save").click(function() {
$.fancybox({
'width' : 560,
'height' : 530,
'autoScale' : false,
'transitionIn' : 'none',
'transitionOut' : 'none',
'type' : 'iframe',
'href' : $(this).attr('href')
});
// example uses a json object to pass data, change here to what you need.
// will also accept jQuery objects like so:
// $.post('recommend.php', $('#myData').serialize());
$.post('recommend.php', { name: 'John', time: '2pm' } );
return false;
});

get file names from uploadify jquery plugin

that is my first post
I am trying here, to get the names of the files that are uploaded, so that the user can delete it if desired, the same way as yahoo.
$("#uploadifysub1").uploadify({
'uploader' : 'JS/uploadify.swf',
'script' : 'JS/uploadify.php',
'cancelImg' : 'cancel.png',
'buttonImg' : 'attach.png',
'folder' : 'uploads',
'queueID' : 'divquickuploadProgress1',
'auto' : true,
'multi' : true
});
the problem is that I cannot get files names, any suggestions?
is there any function in uploadify, that can remove an uploaded file, or I have to do that myself??
Thanks in advance.
thanks to "Codler", I could solve this problem, I will share the code, maybe it will help.
$("#uploadifysub1").uploadify({
'uploader' : 'JS/uploadify.swf',
'script' : 'JS/uploadify.php',
'cancelImg' : 'cancel.png',
'buttonImg' : 'attach.png',
'folder' : 'uploads',
'queueID' : 'divquickuploadProgress1',
'auto' : true,
'multi' : true,
'onComplete' : function(event, queueID, fileObj, reposnse, data) {
// write your own implementation
}
});
my implementation was like that
var cod = '<tr>';
cod += '<td align="left">'+fileObj.name+'</td>';
cod += '<td align="left">';
cod += '<span onclick="removeprev(this,'+fileObj.name+')" style="cursor: pointer;"> ';
cod += '[remove]</span>';
cod += '</td>';
cod += '</tr>';
$('#uploaded_files').append(cod);
Thanks again
Quote from uploadify
fileDataName
The name of your files array in the
upload server script. Default =
‘Filedata’
PHP code
$_FILES['Filedata']['tmp_name'];
why didn't you just set the removeCompleted option to false. It queues all the uploaded files.

javascript to php question

<script type="text/javascript">
$(document).ready(function() {
$("#uploadify").uploadify({
'uploader' : 'scripts/uploadify.swf',
'script' : 'scripts/uploadify.php',
'buttonImg' : 'css/btn_browseFiles.png',
'rollover' : 'true',
'wmode' : 'transparent',
'height' : '26px',
'width' : '109px',
'cancelImg' : 'cancel.png',
'folder' : 'uploads',
'queueID' : 'fileQueue',
'simUploadLimit' : '2',
'auto' : true,
'multi' : true,
'onComplete' : function(event, queueID, fileObj, response, data) {
$('#filesUploaded').append('<li><strong>file:</strong> '+fileName+'</li>');
}
});
});
</script>
I want to get the "+fileName+" to echo in PHP so I can pass it in a contact form.
<?php $que = ""; ?>` fill in the blanks
<input type="hidden" name="" value="<?php echo($que); ?>">
Besides doing the following, I don't know of a way to pass Javascript variables to PHP...
<script type="text/javascript>
location.href="thisPage.php?fileName=" + fileName;
</script>
And then you would use PHP to do:
<?PHP $que = $_GET["fileName"]; ?>
If you want to use the text in the filename variable, you will need to pass it to a server request somehow.
It can be done several ways:
cookie
getline variable/query string
post variable (put it in a form element)
If you just want to get it into a value on the current page, you should be able to use javascript to do it:
#('#id_of_element').val(filename);
This is assuming you are using jQuery.
This looks like some sort of uploading flash component. If it is uploading the file to your server, then you should be able to intercept the request and work with it from there.
$trigger('uploadifyComplete',ID,{
'name' : event.currentTarget.name,
'filePath' : getFolderPath() + '/' + event.currentTarget.name,
'size' : event.currentTarget.size,
'creationDate' : event.currentTarget.creationDate,
'modificationDate' : event.currentTarget.modificationDate,
'type' : event.currentTarget.type
},
can you see these?so you can use fileObj.name to get file name.

Categories