From 18c6018b2429fdb6186a8f8c114547cd4f7131dc Mon Sep 17 00:00:00 2001 From: plegall Date: Tue, 29 Jun 2010 18:39:48 +0000 Subject: bug 1747 fixed: some checks were added to verify the upload will fail for a too big size or if the upload has failed for a too big size (test on upload_max_filesize and post_max_size) git-svn-id: http://piwigo.org/svn/branches/2.1@6624 68402e56-0260-453c-a942-63ccdbb3a9ee --- admin/photos_add_direct.php | 80 +++++++++++++++++++++++++++++++++++++++------ 1 file changed, 70 insertions(+), 10 deletions(-) (limited to 'admin/photos_add_direct.php') diff --git a/admin/photos_add_direct.php b/admin/photos_add_direct.php index 6a7aea884..1026abd17 100644 --- a/admin/photos_add_direct.php +++ b/admin/photos_add_direct.php @@ -62,15 +62,33 @@ DELETE FROM '.CADDIE_TABLE.' // | process form | // +-----------------------------------------------------------------------+ -if (isset($_POST['submit_upload'])) +if (isset($_GET['processed'])) { // echo '
POST'."\n"; print_r($_POST); echo '
'; // echo '
FILES'."\n"; print_r($_FILES); echo '
'; // echo '
SESSION'."\n"; print_r($_SESSION); echo '
'; // exit(); + + // sometimes, you have submitted the form but you have nothing in $_POST + // and $_FILES. This may happen when you have an HTML upload and you + // exceeded the post_max_size (but not the upload_max_size) + if (!isset($_POST['submit_upload'])) + { + array_push( + $page['errors'], + sprintf( + l10n('The uploaded files exceed the post_max_size directive in php.ini: %sB'), + ini_get('post_max_size') + ) + ); + } $category_id = null; - if ('existing' == $_POST['category_type']) + if (!isset($_POST['category_type'])) + { + // nothing to do, we certainly have the post_max_size issue + } + elseif ('existing' == $_POST['category_type']) { $category_id = $_POST['category']; } @@ -193,6 +211,19 @@ if (isset($_POST['submit_upload'])) // TODO: if $image_id is not an integer, something went wrong } } + else + { + $error_message = file_upload_error_message($error); + + array_push( + $page['errors'], + sprintf( + l10n('Error on file "%s" : %s'), + $_FILES['image_upload']['name'][$idx], + $error_message + ) + ); + } } $endtime = get_moment(); @@ -204,21 +235,32 @@ if (isset($_POST['submit_upload'])) if (isset($_POST['upload_id'])) { // we're on a multiple upload, with uploadify and so on - $image_ids = $_SESSION['uploads'][ $_POST['upload_id'] ]; + if (isset($_SESSION['uploads_error'][ $_POST['upload_id'] ])) + { + foreach ($_SESSION['uploads_error'][ $_POST['upload_id'] ] as $error) + { + array_push($page['errors'], $error); + } + } - associate_images_to_categories( - $image_ids, - array($category_id) - ); + if (isset($_SESSION['uploads'][ $_POST['upload_id'] ])) + { + $image_ids = $_SESSION['uploads'][ $_POST['upload_id'] ]; - $query = ' + associate_images_to_categories( + $image_ids, + array($category_id) + ); + + $query = ' UPDATE '.IMAGES_TABLE.' SET level = '.$_POST['level'].' WHERE id IN ('.implode(', ', $image_ids).') ;'; - pwg_query($query); + pwg_query($query); - invalidate_user_cache(); + invalidate_user_cache(); + } } $page['thumbnails'] = array(); @@ -325,6 +367,10 @@ $template->assign( array( 'F_ADD_ACTION'=> PHOTOS_ADD_BASE_URL, 'uploadify_path' => $uploadify_path, + 'upload_max_filesize' => min( + get_ini_size('upload_max_filesize'), + get_ini_size('post_max_size') + ), ) ); @@ -345,10 +391,12 @@ $upload_switch = $upload_modes[ ($upload_mode_index + 1) % 2 ]; $template->assign( array( 'upload_mode' => $upload_mode, + 'form_action' => PHOTOS_ADD_BASE_URL.'&upload_mode='.$upload_mode.'&processed=1', 'switch_url' => PHOTOS_ADD_BASE_URL.'&upload_mode='.$upload_switch, 'upload_id' => md5(rand()), 'session_id' => session_id(), 'pwg_token' => get_pwg_token(), + 'another_upload_link' => PHOTOS_ADD_BASE_URL.'&upload_mode='.$upload_mode, ) ); @@ -464,6 +512,18 @@ if ($conf['use_exif'] and !function_exists('read_exif_data')) ); } +if (get_ini_size('upload_max_filesize') > get_ini_size('post_max_size')) +{ + array_push( + $setup_warnings, + sprintf( + l10n('In your php.ini file, the upload_max_filesize (%sB) is bigger than post_max_size (%sB), you should change this setting'), + get_ini_size('upload_max_filesize', false), + get_ini_size('post_max_size', false) + ) + ); +} + $template->assign( array( 'setup_errors'=> $setup_errors, -- cgit v1.2.3