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.
Related
I am using uplodify to upload files to my server.
It is working with no issue in Google Chrome. But when I try to upload a file using Firefox I get HTTP Error 302 and the file does not uploaded.
Here is my script
<?php $timestamp = time();?>
$('#file_upload').uploadify({
'formData' : {
'timestamp' : '<?php echo $timestamp;?>',
'token' : '<?php echo md5($timestamp);?>',
'session' : '<?php echo $session->currentSessionID(); ?>',
'upload_path': 'ticketing_center/',
'allowed_extentions': 'jpg,jpeg,gif,PNG,JPG,png,JPEG,pdf,jpeg,zip,rar,doc,docx,csv,xls,xlsx,txt,csv,xml'
},
'auto' : true,
'removeCompleted': true,
'swf' : '../../includes/uploadify.swf',
'onError' : function(event, queueID, fileObj, errorObj) { alert(errorObj.type + ' ' + errorObj.info ); },
'uploader' : '../../includes/uploadify.php',
'fileSizeLimit' : '20MB',
'fileTypeExts' : '*.gif; *.jpg; *.JPG; *.png; *.PNG; *.JPEG; *.pdf; *.jpeg; *.zip; *.rar; *.doc; *.docx; *.csv; *.xls; *.xlsx; *.txt; *.csv; *.xml;',
'onUploadSuccess' : function(file, data, response) {
if(response === true){
$('#attached_files').append('<input type="hidden" class="uploadedFiles" name="attachments[]" value="' + $.trim(data) + '" />');
$('#queue_final').append('<div style="display: block;" class="removeFile" id="' + $.trim(data) + '">(x) ' + file.name + '</div>');
} else {
alert('Invalid File Type');
}
$('.removeFile').click( function(){
var file_name = $(this).attr('id');
$( "#dialog-confirm" ).dialog( "open" ).data('file_name', file_name);;
});
}
});
I have done research prior posting this question but none of the solutions that I found solved my problem.
here is what I have tried so far
I have tried adding the session value to the script a 'session' : '<?php echo $session->currentSessionID(); ?>'
Then in my uploadify.php code I did
if (array_key_exists('session', $_REQUEST))
session_id($_REQUEST['session']);
I tried adding header( " HTTP/1.0 200 OK" ); to the top of my PHP script and that did not work as well.
I have tried to add the onError function to display any error but that is not displaying anything.
I am not sure what else could be causing this? Note that it is working on Chrome with no issues.
Here is a screenshot of the error after trying to upload
I am using Firefox 32.0.3.
My Apache is running in Windows Server 2008 R2 I am not sure if this make a difference.
Flash will not pass through your existing PHP Session information, so if you are getting the 302 error it is likely that your application is returning the login URL to the Flash player. To resolve this issue, you could include the session information in scriptData and manage it manually in your application.
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.
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.
I'm trying to upload files to GalleryCMS, but I get an HTTP error 500 each time.
I checked every webpage possible, I changed my php.ini, the execution time to 1200, the upload max to 300mb, I changed the sizelimit to 200MB, I tried to change modsecurity in the .htaccess file, the problem was not there.
I am able to upload any file upto 2MB, anything more I get HTTP error 500. Would any of you guys have any new ideas regarding this ? I got dead ends with most of the sites I visited.
Below is my uploadify script (it came along with GalleryCMS, I haven't changed it much, except for the size limit) :
$('#file_upload').uploadify({
'uploader' : '<?php echo base_url(); ?>flash/uploadify.swf',
'script' : '<?php echo base_url(); ?>index.php/api/upload/<?php echo $album->id; ?>',
'cancelImg' : '<?php echo base_url(); ?>images/cancel.png',
'folder' : '/uploads',
'auto' : false,
'multi' : true,
'scriptData' : { 'user_id' : '<?php echo $user_id; ?>' },
'fileExt' : '*.jpg;*.jpeg;*.gif;*.png',
'fileDesc' : 'Image files',
'sizeLimit' : 209715200, // 200MB
'wmode' : 'opaque',
'onSelect' : function(event, ID, fileObj) {
$('#upload-btn').show();
},
'onCancel' : function(event, ID, fileObj) {
$('#upload-btn').hide();
},
'onError' : function(event, ID, fileObj, errorObj) {
},
'onComplete' : function(event, ID, fileObj, response, data) {
var fileName = response;
$('#upload-btn').hide();
$('#new-images').show();
$.ajax({
url : '<?php echo base_url(); ?>index.php/album/resize/<?php echo $album->id; ?>/' + response,
type : 'POST',
cache : false,
success : function(response) {
if (response !== 'failure') {
var new_image = '<li><img src="<?php echo base_url(); ?>uploads/' + response + '" /><br />' + response + '</li>';
$('#new-image-list').append(new_image);
} else {
var fail_message = '<li>Thumbnail creation failed for: ' + fileObj.name + '</li>';
$('#new-image-list').append(fail_message);
}
},
error : function(jqXHR, textStatus, errorThrown) {
alert('Error occurred when generating thumbnails.');
}
});
}
});
To check it by yourself, the url is GalleryMe
username: test#test.com
password: 12345
Since you are using shared hosting, I am pretty sure you are experiencing a problem with your shared host configuration. As tells your phpinfo(); you are using Apache/2 with FastCGI.
I think that the MaxRequestLength of the FastCGI Apache module is set too low by your host provider.
If possible, you need to add this block to your VirtualHost config :
# Work around annoying fcgid limitations
<IfModule mod_fcgid.c>
# 20MB should be enough
MaxRequestLen 20000000
</IfModule>
If not, you have either to contact your provider or to change provider.
i am trying to use uploadify, to upload pdf or txt files, but without success. Uploadify 2.1.4 uploads just image files. I tried to just rename file extensions, tried to allow ., tried to namely allow pdf or other formats, but Uploadify uploads just F******g images and i do not know why...
Please help me.
I use these settings:
public function show()
{
if(!$this->dir) throw new exception("Upload dir is not set");
if(!$this->url) throw new exception("Upload url is not set");
$rem=(isset($_POST[$this->name."-rem"]))?$_POST[$this->name."-rem"]:"";
$tpl='<div id="'.$this->name.'-queue" class="upload-queue">'.$this->fillQueue().'</div>';
$tpl.='<input id="'.$this->name.'-uploadify" name="'.$this->name.'-uploadify" type="file" />';
$tpl.='<input id="'.$this->name.'-files" name="'.$this->name.'-files" type="hidden" />';
$tpl.='<input id="'.$this->name.'-rem" name="'.$this->name.'-rem" type="hidden" value="'.$rem.'"/>';
//$tpl.='<link rel="stylesheet" type="text/css" href="/uploadify/uploadify.css" />';
$tpl.="<script type=\"text/javascript\"><!--
var ".$this->name."Files=".$this->currentCount.";
function ".$this->name."DeleteFile(where)
{
var rem=$('#".$this->name."-rem').val();
if(rem!='') rem+=',';
$('#".$this->name."-rem').val(rem+$(where).parent().attr('id'));
$(where).parent().remove();
".$this->name."Files--;
if(".$this->name."Files<".$this->count.") $(\"#".$this->name."-uploadifyUploader\").show();
}
$(document).ready(function() {
$(\"#".$this->name."-uploadify\").uploadify({
'uploader' : '/uploadify/uploadify.swf',
'script' : '".$this->url."',
'scriptData' : {'".session_name()."':'".session_id()."'},
'cancelImg' : '/uploadify/cancel.png',
'folder' : '".$this->dir."/thumb',
'queueID' : '".$this->name."-queue',
'auto' : true,
'multi' : ".(($this->count>1)?"true":"false").",
'buttonText' : '".$this->buttonName."',
'fileExt' : '".rtrim($this->fileExt,";")."',
'fileDesc' : '".rtrim($this->fileDesc,",")."',
onError : function (a, b, c, d) {
if (d.status == 404)
alert('Could not find upload script. Use a path relative to: '+'<?= getcwd() ?>');
else if (d.type === \"HTTP\")
alert('error '+d.type+\": \"+d.status);
else if (d.type ===\"File Size\")
alert(c.name+' '+d.type+' Limit: '+Math.round(d.sizeLimit/1024)+'KB');
else
alert('error '+d.type+\": \"+d.text);
},
onComplete : function(event, queueID, fileObj, response, data){
$(\"#".$this->name."-queue\").append('<div id=\"'+fileObj.filePath+'\" class=\"item\"><div style=\"background: url('+fileObj.filePath+') no-repeat 50% 50%\"></div><img src=\"/uploadify/cancel.png\" class=\"delete-file\" onclick=\"".$this->name."DeleteFile(this);\"></div>');
$('#".$this->name."-queue').sortable('refresh');
".$this->name."Files++;
if(".$this->name."Files>=".$this->count.") $(\"#".$this->name."-uploadifyUploader\").hide();
},
onInit : function(){setTimeout(function(){if(".$this->name."Files>=".$this->count.") $(\"#".$this->name."-uploadifyUploader\").hide();},500);}
});
$('#".$this->name."-queue').sortable();
$('#".$this->name."-queue').disableSelection();
$('form').submit(function(){
$('#".$this->name."-files').val($('#".$this->name."-queue').sortable('toArray'));
});
});
--></script>";
return array("",$tpl);
}
...
Thank you!
var settingObject = {
'uploader' : '/uploadify/uploadify.swf', // set your path
'checkScript':'/uploadify/check.php', // set your path
'script' : '/uploadify/uploadify.php', // set your path
'cancelImg' : '/uploadify/cancel.png', // set your path
'folder' : '/files/useruploads',
'auto' : true,
'fileExt' : '*.jpg;*.gif;*.png;*.txt;*.pdf;*.doc;*.docx', // any extension you want to allow
'fileDesc' : 'Upload Files (.JPG, .GIF, .PNG, .TXT, .PDF, .DOC, .DOCX)',
'removeCompleted': false
};
$("#file-1").uploadify(settingObject);
Reference : (File-Extension) http://www.uploadify.com/documentation/options/fileext/
This should work for you..
There might be an issue of Size Limit for each file. Try adding the following
'sizeLimit': 500000
Try to edit upload_max_filesize in your php.ini
Change your current options to these:
$('#file_upload').uploadify({
'uploader' : '/uploadify/uploadify.swf',
'script' : '/uploadify/uploadify.php',
'cancelImg' : '/uploadify/cancel.png',
'folder' : '/uploads',
'fileTypeExt' : '*.jpg;*.gif;*.png', <== this line
'fileTypeDesc' : 'Image Files'
});
For reference: http://www.uploadify.com/documentation/uploadify/filetypeexts/
Change these lines:
'fileTypeExt' : '*.txt;*.pdf;',
'fileTypeDesc' : '*.txt and *.pdf',
Use 'fileExt' : '*.pdf;*.jpg;*.jpeg;*.png', instead of the filename that reads it.