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.
Related
I am trying to use UploadiFive to upload some files and, as they are uploaded, add information to a database about them. The user enters some details in a form and then clicks upload, at which point the file is uploaded and the information from the form is added to the database with corresponding file name.
I've got it working uploading files, but I need the form to post every time a file is completed uploading. It's posting the form but I'm struggling to get the file name from the uploaded file. Code below:
The HTML page:
<?php echo form_open_multipart('upload/do_upload', 'id="upload_form" name="upload_form"');?>
<div id="queue"></div>
<input id="file_upload" name="file_upload" type="file" multiple="true">
<div id="target"></div>
</form>
<script type="text/javascript">
<?php $timestamp = time();?>
$(function() {
$('#file_upload').uploadifive({
'auto' : true,
'checkScript' : '<? echo base_url();?>uploadify/check-exists.php',
'formData' : {
'timestamp' : '<?php echo $timestamp;?>',
'token' : '<?php echo md5('unique_salt' . $timestamp);?>'
},
'queueID' : 'queue',
'onError' : function(errorType) {
alert('The error was: ' + errorType);
},
'uploadScript' : '<? echo base_url();?>uploadify/uploadifive.php',
'onUploadComplete' : function (event, queueID, fileObj, response, data, file) {
//Post response back to controller
$.post('<?php echo site_url('upload/do_upload');?>', {
field1: $("#field1").val(),
field2: $("#field2").val(),
field3: $("#field3").val(),
field4: $("#field4").val(),
checkbox1: $("#checkbox1:checked").val(),
field5: $("#field5").val(),
filearray : response},
function(info){
$("#target").append(info); //Add response returned by controller
});
}
});
});
</script>
Then my controller:
//Decode JSON returned
$file = $this->input->post('filearray');
$json_decoded = json_decode($file);
// Get the image filename & full filename with path
$image_file = $json_decoded->{'file_name'};
$path = "assets/photos/highres/".$image_file;
echo "IMAGE FILE NAME: " . $image_file; die;
For debugging purposes, I just did an echo of $image_file.
It seems to be submitting everything except the response from the uploadifive.php script. When I use Firebug I can see that I do get a response, and it looks correct, but the response (filearray) isn't being posted to the form to be decoded.
Any ideas as to why I can't get the filename from the response?
TL;DR
Use event.name in onUploadComplete:function(event,data){}
If you really need the server's response, then you might want to use data (unfortunately, I can't test it but the documentation wouldn't lie, would it ?).
The details
The documentation for onUploadComplete tells us the following:
onUploadComplete
Input Type
function
Overridable
N/A
Triggered once for each file upload that completes.
Arguments
file
The file object that was uploaded
data
The data returned from the server-side upload script (echoed in uploadifive.php)
Demo
$(function() {
$('#file_upload').uploadifive({
'uploadScript' : '/uploadifive.php'
'onUploadComplete' : function(file, data) {
alert('The file ' + file.name + ' uploaded successfully.');
}
});
});
This is quite different from what is in your code:
'onUploadComplete' : function (event, queueID, fileObj, response, data, file) {...}
I could not test UploadiFive, but did a quick check with Uploadify:
'onUploadComplete' : function(event) {
console.log(JSON.stringify(event,null,4));
}
Which returned this output:
{
"size": 34405,
"post": {},
"modificationdate": "2015-09-21T02:24:51.597Z",
"name": "Tire-wheel-advisor1.jpg",
"creationdate": "2015-09-21T02:24:51.539Z",
"id": "SWFUpload_0_0",
"type": ".jpg",
"filestatus": -4,
"index": 0
}
I Try to integrate my Codeigniter web with uploadify. its work fine in Chrome and even IE, but getting HTTP 302 error when I run my web in Mozilla firefox. and sometimes its show "IO Error" too, I read this post: 302 and IO uploadify error, but still doesnt have idea what I must to do. maybe more detail/clear guide would be help.
this is my uploadify config in view:
$('#shopfile').uploadify({
'debug':false,
'auto':true,
'swf': '<?= base_url(); ?>file/lib/uploadify/uploadify.swf',
'uploader': '<?= base_url(); ?>my_shop/upload_shopheader',
'cancelImg': '<?= base_url(); ?>file/lib/uploadify/uploadify-cancel.png',
'fileTypeExts':'*.jpg;*.jpeg;*.png;',
'fileTypeDesc':'Image Files (.jpg,.jpeg,.png)',
'fileSizeLimit':'2MB',
'fileObjName':'shopfile',
'buttonText':'Select File',
'multi':false,
'removeCompleted':false,
'onUploadError' : function(file, errorCode, errorMsg, errorString) {
alert('The file ' + file.name + ' could not be uploaded: ' + errorString);
$( ".uploadMessageStr" ).html('<div class="alert alert-danger">The file ' + file.name + ' could not be uploaded: ' + errorString + '</div>');
},
'onUploadSuccess' : function(file, data, response){
//some statement..
}
});
and this is my controller / uploader function code :
public function upload_shopheader(){
if (empty($_FILES['shopfile']['name'])) redirect('my_shop/profile');
$config = $this->avatarUploadConfig();
$this->upload->initialize($config);
$data = array();
if (!$this->upload->do_upload('shopfile')) {
//if upload failed...
$upload_error = $this->upload->display_errors();
$data['message'] = "<div class='alert alert-danger'>Upload Failed. ".$upload_error."</div>";
}
else {
//if upload success...
}
echo json_encode($data);
}
Thanks before.
SOLVED with add session id manually through uploadify.
adding this to uploadify config in view:
'formData' : {'SESSION_ID' : '<?= $this->session->userdata('session_id'); ?>'},
and add this code in beginning of controller function:
//check session..
$sess_id = $this->input->post('SESSION_ID');
if(!isset($sess_id)){
redirect('to_some/page');
}
else{
$this->session->set_userdata(array('session_id' => $sess_id));
}
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.
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.
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.