Skip to content

Commit

Permalink
added is_writable() for #38
Browse files Browse the repository at this point in the history
Check if is_writable() on loading contents of folders.
Be carful - currently this is only updated, when a folder is reloaded.
  • Loading branch information
creativecat committed Dec 19, 2012
1 parent bd13c74 commit 1d7ef16
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 10 deletions.
3 changes: 2 additions & 1 deletion upload/backend/media/ajax_get_contents.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ function byte_convert($bytes)

if ( is_dir( $load_path ) )
{
$ajax['is_folder'] = true;
$ajax['is_folder'] = true;
$ajax['is_writable'] = is_writable($load_path);
// ========================================
// ! Get contents for the intitial folder
// ========================================
Expand Down
15 changes: 8 additions & 7 deletions upload/backend/media/upload.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,23 +70,25 @@
$allowed_file_types = explode(',', RENAME_FILES_ON_UPLOAD);
foreach ( $upload_counter as $file_id )
{
$file_name = 'upload_' . $file_id;
$field_name = 'upload_' . $file_id;

if ( isset( $_FILES[$file_name]['name'] ) && $_FILES[$file_name]['name'] != '' )
if ( isset( $_FILES[$field_name]['name'] ) && $_FILES[$field_name]['name'] != '' )
{
// ===========================================
// ! Get file extension of the uploaded file
// ===========================================
$file_extension = (strtolower( pathinfo( $_FILES[$file_name]['name'], PATHINFO_EXTENSION ) ) == '') ? false : strtolower( pathinfo($_FILES[$file_name]['name'], PATHINFO_EXTENSION));
$file_extension = (strtolower( pathinfo( $_FILES[$field_name]['name'], PATHINFO_EXTENSION ) ) == '') ? false : strtolower( pathinfo($_FILES[$field_name]['name'], PATHINFO_EXTENSION));
// ======================================
// ! Check if file extension is allowed
// ======================================
if ( isset( $file_extension ) && in_array( $file_extension, $allowed_file_types ) )
{
echo $field_name;
// =======================================
// ! Try to include the upload.class.php
// =======================================
$files = $admin->get_helper('LEPTON_Helper_Upload', $_FILES[$file_name]);
$files = $admin->get_helper( 'Upload', $_FILES[$field_name] );
echo $files->_handles['Upload']['__args__'];

if ( $files->uploaded )
{
Expand All @@ -99,7 +101,6 @@
{
$files->file_overwrite = false;
}

// Replace with allowed images
//$files->allowed = array('image/*');

Expand Down Expand Up @@ -151,14 +152,14 @@
$admin->print_error( 'An error occurred: ' . $files->error, false );
}
}
else $admin->print_error( 'An error occured:' . $files->error, $files->log, false );
else $admin->print_error( 'An error occurred: ' . $files->error, $files->log, false );
}
else $admin->print_error( 'No file extension were found.', false );
}
}
$admin->print_success('All files have been uploaded successfully.', false );
}
else $admin->print_error( 'File couldn\'t be uploaded. Maybe it is too big?', false );
else $admin->print_error( 'File could not be uploaded. Maybe it is too big?', false );
// ======================
// ! Print admin footer
// ======================
Expand Down
14 changes: 12 additions & 2 deletions upload/templates/freshcat/js/backend_media.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,16 @@ function reload_folder( current_ul, folder_path, load_url )
current_ul.find('.fc_name_short p').smartTruncation({ 'truncateCenter' : true });
// Activate all click-events to the new added list
set_media_functions( current_ul );
console.log(data.is_writable);
if ( !data.is_writable )
{
$('#fc_media_upload_not_writable').removeClass('hidden');
$('#fc_media_index_upload').addClass('hidden');
}
else {
$('#fc_media_index_upload').removeClass('hidden');
$('#fc_media_upload_not_writable').addClass('hidden');
}
}
else
{
Expand Down Expand Up @@ -608,7 +618,7 @@ jQuery(document).ready(function()
});

// Activate the upload form to send data with ajax
dialog_form(
/* dialog_form(
$('#fc_media_index_upload'), function( data )
{
var current_ul = get_active_media(),
Expand All @@ -631,5 +641,5 @@ jQuery(document).ready(function()
$('#fc_media_index_upload').find('input[type="reset"]').click();
}
);
);*/
});
1 change: 1 addition & 0 deletions upload/templates/freshcat/templates/form_upload_files.lte
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<ul class="fc_br_bottom fc_br_topleft fc_gradient1 fc_shadow_small" id="fc_media_index_upload_ul">
<li>
<div id="fc_media_upload_not_writable" class="hidden">{translate('Please note: This folder is not writable! You cannot upload files to it!')}</div>
<form name="upload" action="{$ADMIN_URL}/media/upload.php" method="post" enctype="multipart/form-data" id="fc_media_index_upload">
<div class="clear">
<input type="hidden" name="form_title" value="{translate('Upload File(s)')}" />
Expand Down

0 comments on commit 1d7ef16

Please sign in to comment.