コード例 #1
0
ファイル: 117-database.php プロジェクト: lcorbasson/Piwigo
// +-----------------------------------------------------------------------+
// | This program is free software; you can redistribute it and/or modify  |
// | it under the terms of the GNU General Public License as published by  |
// | the Free Software Foundation                                          |
// |                                                                       |
// | This program is distributed in the hope that it will be useful, but   |
// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
// | General Public License for more details.                              |
// |                                                                       |
// | You should have received a copy of the GNU General Public License     |
// | along with this program; if not, write to the Free Software           |
// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
// | USA.                                                                  |
// +-----------------------------------------------------------------------+
if (!defined('PHPWG_ROOT_PATH')) {
    die('Hacking attempt!');
}
$upgrade_description = 'fill empty images name with filename';
include_once PHPWG_ROOT_PATH . 'include/constants.php';
// +-----------------------------------------------------------------------+
// |                            Upgrade content                            |
// +-----------------------------------------------------------------------+
$query = 'SELECT id, file FROM ' . IMAGES_TABLE . ' WHERE name IS NULL;';
$images = pwg_query($query);
$updates = array();
while ($row = pwg_db_fetch_assoc($images)) {
    $updates[] = array('id' => $row['id'], 'name' => get_name_from_file($row['file']));
}
mass_updates(IMAGES_TABLE, array('primary' => array('id'), 'update' => array('name')), $updates);
echo "\n" . '"' . $upgrade_description . '"' . ' ended' . "\n";
コード例 #2
0
ファイル: site_update.php プロジェクト: squidjam/Piwigo
 $start = get_moment();
 $inserts = array();
 $insert_links = array();
 foreach (array_diff(array_keys($fs), $db_elements) as $path) {
     $insert = array();
     // storage category must exist
     $dirname = dirname($path);
     if (!isset($db_fulldirs[$dirname])) {
         continue;
     }
     $filename = basename($path);
     if (!preg_match($conf['sync_chars_regex'], $filename)) {
         $errors[] = array('path' => $path, 'type' => 'PWG-UPDATE-1');
         continue;
     }
     $insert = array('id' => $next_element_id++, 'file' => $filename, 'name' => get_name_from_file($filename), 'date_available' => CURRENT_DATE, 'path' => $path, 'representative_ext' => $fs[$path]['representative_ext'], 'storage_category_id' => $db_fulldirs[$dirname], 'added_by' => $user['id']);
     if ($_POST['privacy_level'] != 0) {
         $insert['level'] = $_POST['privacy_level'];
     }
     $inserts[] = $insert;
     $insert_links[] = array('image_id' => $insert['id'], 'category_id' => $insert['storage_category_id']);
     $infos[] = array('path' => $insert['path'], 'info' => l10n('added'));
     $caddiables[] = $insert['id'];
 }
 if (count($inserts) > 0) {
     if (!$simulate) {
         // inserts all new elements
         mass_inserts(IMAGES_TABLE, array_keys($inserts[0]), $inserts);
         // inserts all links between new elements and their storage category
         mass_inserts(IMAGE_CATEGORY_TABLE, array_keys($insert_links[0]), $insert_links);
         // add new photos to caddie
コード例 #3
0
ファイル: batch_manager_unit.php プロジェクト: donseba/Piwigo
    }
    $query .= '
  ' . $conf['order_by'] . '
  LIMIT ' . $page['nb_images'] . ' OFFSET ' . $page['start'] . '
;';
    $result = pwg_query($query);
    while ($row = pwg_db_fetch_assoc($result)) {
        $element_ids[] = $row['id'];
        $src_image = new SrcImage($row);
        $query = '
SELECT
    id,
    name
  FROM ' . IMAGE_TAG_TABLE . ' AS it
    JOIN ' . TAGS_TABLE . ' AS t ON t.id = it.tag_id
  WHERE image_id = ' . $row['id'] . '
;';
        $tag_selection = get_taglist($query);
        $legend = render_element_name($row);
        if ($legend != get_name_from_file($row['file'])) {
            $legend .= ' (' . $row['file'] . ')';
        }
        $template->append('elements', array_merge($row, array('ID' => $row['id'], 'TN_SRC' => DerivativeImage::url(IMG_THUMB, $src_image), 'FILE_SRC' => DerivativeImage::url(IMG_LARGE, $src_image), 'LEGEND' => $legend, 'U_EDIT' => get_root_url() . 'admin.php?page=photo-' . $row['id'], 'NAME' => htmlspecialchars(@$row['name']), 'AUTHOR' => htmlspecialchars(@$row['author']), 'LEVEL' => !empty($row['level']) ? $row['level'] : '0', 'DESCRIPTION' => htmlspecialchars(@$row['comment']), 'DATE_CREATION' => $row['date_creation'], 'TAGS' => $tag_selection)));
    }
    $template->assign(array('ELEMENT_IDS' => implode(',', $element_ids), 'CACHE_KEYS' => get_admin_client_cache_keys(array('tags'))));
}
trigger_notify('loc_end_element_set_unit');
// +-----------------------------------------------------------------------+
// |                           sending html code                           |
// +-----------------------------------------------------------------------+
$template->assign_var_from_handle('ADMIN_CONTENT', 'batch_manager_unit');
コード例 #4
0
/**
 * Returns display name for an element.
 * Returns 'name' if exists of name from 'file'.
 *
 * @param array $info at least file or name
 * @return string
 */
function render_element_name($info)
{
    if (!empty($info['name'])) {
        return trigger_change('render_element_name', $info['name']);
    }
    return get_name_from_file($info['file']);
}
コード例 #5
0
        $query .= '
    JOIN ' . IMAGE_CATEGORY_TABLE . ' ON id = image_id';
    }
    $query .= '
  WHERE id IN (' . implode(',', $page['cat_elements_id']) . ')';
    if ($is_category) {
        $query .= '
    AND category_id = ' . $_SESSION['bulk_manager_filter']['category'];
    }
    $query .= '
  ' . $conf['order_by'] . '
  LIMIT ' . $page['nb_images'] . ' OFFSET ' . $page['start'] . '
;';
    $result = pwg_query($query);
    $thumb_params = ImageStdParams::get_by_type(IMG_THUMB);
    // template thumbnail initialization
    while ($row = pwg_db_fetch_assoc($result)) {
        $nb_thumbs_page++;
        $src_image = new SrcImage($row);
        $ttitle = render_element_name($row);
        if ($ttitle != get_name_from_file($row['file'])) {
            $ttitle .= ' (' . $row['file'] . ')';
        }
        $template->append('thumbnails', array_merge($row, array('thumb' => new DerivativeImage($thumb_params, $src_image), 'TITLE' => $ttitle, 'FILE_SRC' => DerivativeImage::url(IMG_LARGE, $src_image), 'U_EDIT' => get_root_url() . 'admin.php?page=photo-' . $row['id'])));
    }
    $template->assign('thumb_params', $thumb_params);
}
$template->assign(array('nb_thumbs_page' => $nb_thumbs_page, 'nb_thumbs_set' => count($page['cat_elements_id']), 'CACHE_KEYS' => get_admin_client_cache_keys(array('tags', 'categories'))));
trigger_notify('loc_end_element_set_global');
//----------------------------------------------------------- sending html code
$template->assign_var_from_handle('ADMIN_CONTENT', 'batch_manager_global');
コード例 #6
0
ファイル: comments.php プロジェクト: donseba/Piwigo
    $query = '
SELECT *
  FROM ' . IMAGES_TABLE . '
  WHERE id IN (' . implode(',', $element_ids) . ')
;';
    $elements = query2array($query, 'id');
    // retrieving category informations
    $query = 'SELECT id, name, permalink, uppercats
  FROM ' . CATEGORIES_TABLE . '
  WHERE id IN (' . implode(',', $category_ids) . ')';
    $categories = query2array($query, 'id');
    foreach ($comments as $comment) {
        if (!empty($elements[$comment['image_id']]['name'])) {
            $name = $elements[$comment['image_id']]['name'];
        } else {
            $name = get_name_from_file($elements[$comment['image_id']]['file']);
        }
        // source of the thumbnail picture
        $src_image = new SrcImage($elements[$comment['image_id']]);
        // link to the full size picture
        $url = make_picture_url(array('category' => $categories[$comment['category_id']], 'image_id' => $comment['image_id'], 'image_file' => $elements[$comment['image_id']]['file']));
        $email = null;
        if (!empty($comment['user_email'])) {
            $email = $comment['user_email'];
        } else {
            if (!empty($comment['email'])) {
                $email = $comment['email'];
            }
        }
        $tpl_comment = array('ID' => $comment['comment_id'], 'U_PICTURE' => $url, 'src_image' => $src_image, 'ALT' => $name, 'AUTHOR' => trigger_change('render_comment_author', $comment['author']), 'WEBSITE_URL' => $comment['website_url'], 'DATE' => format_date($comment['date'], array('day_name', 'day', 'month', 'year', 'time')), 'CONTENT' => trigger_change('render_comment_content', $comment['content']));
        if (is_admin()) {
コード例 #7
0
function add_uploaded_file($source_filepath, $original_filename = null, $categories = null, $level = null, $image_id = null, $original_md5sum = null)
{
    // 1) move uploaded file to upload/2010/01/22/20100122003814-449ada00.jpg
    //
    // 2) keep/resize original
    //
    // 3) register in database
    // TODO
    // * check md5sum (already exists?)
    global $conf, $user;
    if (isset($original_md5sum)) {
        $md5sum = $original_md5sum;
    } else {
        $md5sum = md5_file($source_filepath);
    }
    $file_path = null;
    $is_tiff = false;
    if (isset($image_id)) {
        // this photo already exists, we update it
        $query = '
SELECT
    path
  FROM ' . IMAGES_TABLE . '
  WHERE id = ' . $image_id . '
;';
        $result = pwg_query($query);
        while ($row = pwg_db_fetch_assoc($result)) {
            $file_path = $row['path'];
        }
        if (!isset($file_path)) {
            die('[' . __FUNCTION__ . '] this photo does not exist in the database');
        }
        // delete all physical files related to the photo (thumbnail, web site, HD)
        delete_element_files(array($image_id));
    } else {
        // this photo is new
        // current date
        list($dbnow) = pwg_db_fetch_row(pwg_query('SELECT NOW();'));
        list($year, $month, $day) = preg_split('/[^\\d]/', $dbnow, 4);
        // upload directory hierarchy
        $upload_dir = sprintf(PHPWG_ROOT_PATH . $conf['upload_dir'] . '/%s/%s/%s', $year, $month, $day);
        // compute file path
        $date_string = preg_replace('/[^\\d]/', '', $dbnow);
        $random_string = substr($md5sum, 0, 8);
        $filename_wo_ext = $date_string . '-' . $random_string;
        $file_path = $upload_dir . '/' . $filename_wo_ext . '.';
        list($width, $height, $type) = getimagesize($source_filepath);
        if (IMAGETYPE_PNG == $type) {
            $file_path .= 'png';
        } elseif (IMAGETYPE_GIF == $type) {
            $file_path .= 'gif';
        } elseif (IMAGETYPE_TIFF_MM == $type or IMAGETYPE_TIFF_II == $type) {
            $is_tiff = true;
            $file_path .= 'tif';
        } elseif (IMAGETYPE_JPEG == $type) {
            $file_path .= 'jpg';
        } elseif (isset($conf['upload_form_all_types']) and $conf['upload_form_all_types']) {
            $original_extension = strtolower(get_extension($original_filename));
            if (in_array($original_extension, $conf['file_ext'])) {
                $file_path .= $original_extension;
            } else {
                die('unexpected file type');
            }
        } else {
            die('forbidden file type');
        }
        prepare_directory($upload_dir);
    }
    if (is_uploaded_file($source_filepath)) {
        move_uploaded_file($source_filepath, $file_path);
    } else {
        rename($source_filepath, $file_path);
    }
    @chmod($file_path, 0644);
    if ($is_tiff and pwg_image::get_library() == 'ext_imagick') {
        // move the uploaded file to pwg_representative sub-directory
        $representative_file_path = dirname($file_path) . '/pwg_representative/';
        $representative_file_path .= get_filename_wo_extension(basename($file_path)) . '.';
        $representative_ext = $conf['tiff_representative_ext'];
        $representative_file_path .= $representative_ext;
        prepare_directory(dirname($representative_file_path));
        $exec = $conf['ext_imagick_dir'] . 'convert';
        if ('jpg' == $conf['tiff_representative_ext']) {
            $exec .= ' -quality 98';
        }
        $exec .= ' "' . realpath($file_path) . '"';
        $dest = pathinfo($representative_file_path);
        $exec .= ' "' . realpath($dest['dirname']) . '/' . $dest['basename'] . '"';
        $exec .= ' 2>&1';
        @exec($exec, $returnarray);
        // sometimes ImageMagick creates file-0.jpg (full size) + file-1.jpg
        // (thumbnail). I don't know how to avoid it.
        $representative_file_abspath = realpath($dest['dirname']) . '/' . $dest['basename'];
        if (!file_exists($representative_file_abspath)) {
            $first_file_abspath = preg_replace('/\\.' . $representative_ext . '$/', '-0.' . $representative_ext, $representative_file_abspath);
            if (file_exists($first_file_abspath)) {
                rename($first_file_abspath, $representative_file_abspath);
            }
        }
    }
    //
    // generate pwg_representative in case of video
    //
    $ffmpeg_video_exts = array('wmv', 'mov', 'mkv', 'mp4', 'mpg', 'flv', 'asf', 'xvid', 'divx', 'mpeg', 'avi', 'rm');
    if (isset($original_extension) and in_array($original_extension, $ffmpeg_video_exts)) {
        $representative_file_path = dirname($file_path) . '/pwg_representative/';
        $representative_file_path .= get_filename_wo_extension(basename($file_path)) . '.';
        $representative_ext = 'jpg';
        $representative_file_path .= $representative_ext;
        prepare_directory(dirname($representative_file_path));
        $second = 1;
        $ffmpeg = $conf['ffmpeg_dir'] . 'ffmpeg';
        $ffmpeg .= ' -i "' . $file_path . '"';
        $ffmpeg .= ' -an -ss ' . $second;
        $ffmpeg .= ' -t 1 -r 1 -y -vcodec mjpeg -f mjpeg';
        $ffmpeg .= ' "' . $representative_file_path . '"';
        // file_put_contents('/tmp/ffmpeg.log', "\n==== ".date('c')."\n".__FUNCTION__.' : '.$ffmpeg."\n", FILE_APPEND);
        @exec($ffmpeg);
        if (!file_exists($representative_file_path)) {
            $representative_ext = null;
        }
    }
    if (isset($original_extension) and 'pdf' == $original_extension and pwg_image::get_library() == 'ext_imagick') {
        $representative_file_path = dirname($file_path) . '/pwg_representative/';
        $representative_file_path .= get_filename_wo_extension(basename($file_path)) . '.';
        $representative_ext = 'jpg';
        $representative_file_path .= $representative_ext;
        prepare_directory(dirname($representative_file_path));
        $exec = $conf['ext_imagick_dir'] . 'convert';
        $exec .= ' -quality 98';
        $exec .= ' "' . realpath($file_path) . '"[0]';
        $dest = pathinfo($representative_file_path);
        $exec .= ' "' . realpath($dest['dirname']) . '/' . $dest['basename'] . '"';
        $exec .= ' 2>&1';
        @exec($exec, $returnarray);
    }
    if (pwg_image::get_library() != 'gd') {
        if ($conf['original_resize']) {
            $need_resize = need_resize($file_path, $conf['original_resize_maxwidth'], $conf['original_resize_maxheight']);
            if ($need_resize) {
                $img = new pwg_image($file_path);
                $img->pwg_resize($file_path, $conf['original_resize_maxwidth'], $conf['original_resize_maxheight'], $conf['original_resize_quality'], $conf['upload_form_automatic_rotation'], false);
                $img->destroy();
            }
        }
    }
    // we need to save the rotation angle in the database to compute
    // width/height of "multisizes"
    $rotation_angle = pwg_image::get_rotation_angle($file_path);
    $rotation = pwg_image::get_rotation_code_from_angle($rotation_angle);
    $file_infos = pwg_image_infos($file_path);
    if (isset($image_id)) {
        $update = array('file' => pwg_db_real_escape_string(isset($original_filename) ? $original_filename : basename($file_path)), 'filesize' => $file_infos['filesize'], 'width' => $file_infos['width'], 'height' => $file_infos['height'], 'md5sum' => $md5sum, 'added_by' => $user['id'], 'rotation' => $rotation);
        if (isset($level)) {
            $update['level'] = $level;
        }
        single_update(IMAGES_TABLE, $update, array('id' => $image_id));
    } else {
        // database registration
        $file = pwg_db_real_escape_string(isset($original_filename) ? $original_filename : basename($file_path));
        $insert = array('file' => $file, 'name' => get_name_from_file($file), 'date_available' => $dbnow, 'path' => preg_replace('#^' . preg_quote(PHPWG_ROOT_PATH) . '#', '', $file_path), 'filesize' => $file_infos['filesize'], 'width' => $file_infos['width'], 'height' => $file_infos['height'], 'md5sum' => $md5sum, 'added_by' => $user['id'], 'rotation' => $rotation);
        if (isset($level)) {
            $insert['level'] = $level;
        }
        if (isset($representative_ext)) {
            $insert['representative_ext'] = $representative_ext;
        }
        single_insert(IMAGES_TABLE, $insert);
        $image_id = pwg_db_insert_id(IMAGES_TABLE);
    }
    if (isset($categories) and count($categories) > 0) {
        associate_images_to_categories(array($image_id), $categories);
    }
    // update metadata from the uploaded file (exif/iptc)
    if ($conf['use_exif'] and !function_exists('read_exif_data')) {
        $conf['use_exif'] = false;
    }
    sync_metadata(array($image_id));
    invalidate_user_cache();
    // cache thumbnail
    $query = '
SELECT
    id,
    path
  FROM ' . IMAGES_TABLE . '
  WHERE id = ' . $image_id . '
;';
    $image_infos = pwg_db_fetch_assoc(pwg_query($query));
    set_make_full_url();
    // in case we are on uploadify.php, we have to replace the false path
    $thumb_url = preg_replace('#admin/include/i#', 'i', DerivativeImage::thumb_url($image_infos));
    unset_make_full_url();
    fetchRemote($thumb_url, $dest);
    return $image_id;
}
コード例 #8
0
function add_uploaded_file($source_filepath, $original_filename = null, $categories = null, $level = null, $image_id = null, $original_md5sum = null)
{
    // 1) move uploaded file to upload/2010/01/22/20100122003814-449ada00.jpg
    //
    // 2) keep/resize original
    //
    // 3) register in database
    // TODO
    // * check md5sum (already exists?)
    global $conf, $user;
    if (isset($original_md5sum)) {
        $md5sum = $original_md5sum;
    } else {
        $md5sum = md5_file($source_filepath);
    }
    $file_path = null;
    $is_tiff = false;
    if (isset($image_id)) {
        // this photo already exists, we update it
        $query = '
SELECT
    path
  FROM ' . IMAGES_TABLE . '
  WHERE id = ' . $image_id . '
;';
        $result = pwg_query($query);
        while ($row = pwg_db_fetch_assoc($result)) {
            $file_path = $row['path'];
        }
        if (!isset($file_path)) {
            die('[' . __FUNCTION__ . '] this photo does not exist in the database');
        }
        // delete all physical files related to the photo (thumbnail, web site, HD)
        delete_element_files(array($image_id));
    } else {
        // this photo is new
        // current date
        list($dbnow) = pwg_db_fetch_row(pwg_query('SELECT NOW();'));
        list($year, $month, $day) = preg_split('/[^\\d]/', $dbnow, 4);
        // upload directory hierarchy
        $upload_dir = sprintf(PHPWG_ROOT_PATH . $conf['upload_dir'] . '/%s/%s/%s', $year, $month, $day);
        // compute file path
        $date_string = preg_replace('/[^\\d]/', '', $dbnow);
        $random_string = substr($md5sum, 0, 8);
        $filename_wo_ext = $date_string . '-' . $random_string;
        $file_path = $upload_dir . '/' . $filename_wo_ext . '.';
        list($width, $height, $type) = getimagesize($source_filepath);
        if (IMAGETYPE_PNG == $type) {
            $file_path .= 'png';
        } elseif (IMAGETYPE_GIF == $type) {
            $file_path .= 'gif';
        } elseif (IMAGETYPE_TIFF_MM == $type or IMAGETYPE_TIFF_II == $type) {
            $is_tiff = true;
            $file_path .= 'tif';
        } elseif (IMAGETYPE_JPEG == $type) {
            $file_path .= 'jpg';
        } elseif (isset($conf['upload_form_all_types']) and $conf['upload_form_all_types']) {
            $original_extension = strtolower(get_extension($original_filename));
            if (in_array($original_extension, $conf['file_ext'])) {
                $file_path .= $original_extension;
            } else {
                die('unexpected file type');
            }
        } else {
            die('forbidden file type');
        }
        prepare_directory($upload_dir);
    }
    if (is_uploaded_file($source_filepath)) {
        move_uploaded_file($source_filepath, $file_path);
    } else {
        rename($source_filepath, $file_path);
    }
    @chmod($file_path, 0644);
    // handle the uploaded file type by potentially making a
    // pwg_representative file.
    $representative_ext = trigger_change('upload_file', null, $file_path);
    global $logger;
    $logger->info("Handling " . (string) $file_path . " got " . (string) $representative_ext);
    // If it is set to either true (the file didn't need a
    // representative generated) or false (the generation of the
    // representative failed), set it to null because we have no
    // representative file.
    if (is_bool($representative_ext)) {
        $representative_ext = null;
    }
    if (pwg_image::get_library() != 'gd') {
        if ($conf['original_resize']) {
            $need_resize = need_resize($file_path, $conf['original_resize_maxwidth'], $conf['original_resize_maxheight']);
            if ($need_resize) {
                $img = new pwg_image($file_path);
                $img->pwg_resize($file_path, $conf['original_resize_maxwidth'], $conf['original_resize_maxheight'], $conf['original_resize_quality'], $conf['upload_form_automatic_rotation'], false);
                $img->destroy();
            }
        }
    }
    // we need to save the rotation angle in the database to compute
    // width/height of "multisizes"
    $rotation_angle = pwg_image::get_rotation_angle($file_path);
    $rotation = pwg_image::get_rotation_code_from_angle($rotation_angle);
    $file_infos = pwg_image_infos($file_path);
    if (isset($image_id)) {
        $update = array('file' => pwg_db_real_escape_string(isset($original_filename) ? $original_filename : basename($file_path)), 'filesize' => $file_infos['filesize'], 'width' => $file_infos['width'], 'height' => $file_infos['height'], 'md5sum' => $md5sum, 'added_by' => $user['id'], 'rotation' => $rotation);
        if (isset($level)) {
            $update['level'] = $level;
        }
        single_update(IMAGES_TABLE, $update, array('id' => $image_id));
    } else {
        // database registration
        $file = pwg_db_real_escape_string(isset($original_filename) ? $original_filename : basename($file_path));
        $insert = array('file' => $file, 'name' => get_name_from_file($file), 'date_available' => $dbnow, 'path' => preg_replace('#^' . preg_quote(PHPWG_ROOT_PATH) . '#', '', $file_path), 'filesize' => $file_infos['filesize'], 'width' => $file_infos['width'], 'height' => $file_infos['height'], 'md5sum' => $md5sum, 'added_by' => $user['id'], 'rotation' => $rotation);
        if (isset($level)) {
            $insert['level'] = $level;
        }
        if (isset($representative_ext)) {
            $insert['representative_ext'] = $representative_ext;
        }
        single_insert(IMAGES_TABLE, $insert);
        $image_id = pwg_db_insert_id(IMAGES_TABLE);
    }
    if (isset($categories) and count($categories) > 0) {
        associate_images_to_categories(array($image_id), $categories);
    }
    // update metadata from the uploaded file (exif/iptc)
    if ($conf['use_exif'] and !function_exists('read_exif_data')) {
        $conf['use_exif'] = false;
    }
    sync_metadata(array($image_id));
    invalidate_user_cache();
    // cache thumbnail
    $query = '
SELECT
    id,
    path
  FROM ' . IMAGES_TABLE . '
  WHERE id = ' . $image_id . '
;';
    $image_infos = pwg_db_fetch_assoc(pwg_query($query));
    set_make_full_url();
    // in case we are on uploadify.php, we have to replace the false path
    $thumb_url = preg_replace('#admin/include/i#', 'i', DerivativeImage::thumb_url($image_infos));
    unset_make_full_url();
    fetchRemote($thumb_url, $dest);
    return $image_id;
}
コード例 #9
0
ファイル: edit.php プロジェクト: ewosp/icedeck
     $errors[] = $Lang['Errors']['delete_logo_and_upload_one_error'];
     $_POST['DeleteLogo'] = false;
 }
 if ($_POST['DeleteLogo']) {
     $card->logo = '';
 } elseif ($_FILES['NewLogo']['error'] != 4) {
     #We've a file !
     #We ignore $_FILES[NewLogo][error] 4, this means no file has been uploaded
     #(so user doesn't want upload a new file)
     #See http:/www.php.net/features.file-upload and http://www.php.net/manual/en/features.file-upload.errors.php about common errors
     #Not valid before PHP 4.2.0
     switch ($_FILES['NewLogo']['error']) {
         case 0:
             #There is no error, the file uploaded with success.
             #Gets filename
             $base = get_name_from_file($_FILES['NewLogo']['name']);
             $ext = get_extension_from_file($_FILES['NewLogo']['name']);
             $filename = $base . '.' . $ext;
             $i = 1;
             //counter, for file name appending purpose
             while (file_exists(DIR_LOGOS . $filename)) {
                 #This filename already exists, so we append it with 3-digits numeric value (e.g. 001, 002, ...).
                 #When 999 is overtaken, filename's appended by 1000, 1001, ..., 9999, 10000, ...
                 $filename = $base . zerofill($i, 3) . '.' . $ext;
                 $i++;
             }
             if (!move_uploaded_file($_FILES['NewLogo']['tmp_name'], DIR_LOGOS . $filename)) {
                 $errors[] = $Lang['Errors']['move_upload_error'];
             } else {
                 //Sets logo filename in card data
                 $card->logo = $filename;