Exemple #1
0
 /**
  * Upload function will be called via the Flash uploader
  * 
  * @class nggAdmin
  * @param integer $galleryID
  * @return string $result
  */
 function swfupload_image($galleryID = 0)
 {
     global $wpdb;
     if ($galleryID == 0) {
         return __('No gallery selected !', 'nggallery');
     }
     // WPMU action
     if (nggWPMU::check_quota()) {
         return '0';
     }
     // Check the upload
     if (!isset($_FILES['Filedata']) || !is_uploaded_file($_FILES['Filedata']['tmp_name']) || $_FILES['Filedata']['error'] != 0) {
         return __('Invalid upload. Error Code : ', 'nggallery') . $_FILES['Filedata']['error'];
     }
     // get the filename and extension
     $temp_file = $_FILES['Filedata']['tmp_name'];
     $filepart = nggGallery::fileinfo($_FILES['Filedata']['name']);
     $filename = $filepart['basename'];
     // check for allowed extension
     $ext = array('jpg', 'png', 'gif');
     if (!in_array($filepart['extension'], $ext)) {
         return $_FILES[$key]['name'] . __('is no valid image file!', 'nggallery');
     }
     // get the path to the gallery
     $gallerypath = $wpdb->get_var("SELECT path FROM {$wpdb->nggallery} WHERE gid = '{$galleryID}' ");
     if (!$gallerypath) {
         @unlink($temp_file);
         return __('Failure in database, no gallery path set !', 'nggallery');
     }
     // read list of images
     $imageslist = nggAdmin::scandir(WINABSPATH . $gallerypath);
     // check if this filename already exist
     $i = 0;
     while (in_array($filename, $imageslist)) {
         $filename = $filepart['filename'] . '_' . $i++ . '.' . $filepart['extension'];
     }
     $dest_file = WINABSPATH . $gallerypath . '/' . $filename;
     // save temp file to gallery
     if (!@move_uploaded_file($_FILES["Filedata"]['tmp_name'], $dest_file)) {
         nggAdmin::check_safemode(WINABSPATH . $gallerypath);
         return __('Error, the file could not be moved to : ', 'nggallery') . $dest_file;
     }
     if (!nggAdmin::chmod($dest_file)) {
         return __('Error, the file permissions could not be set', 'nggallery');
     }
     return '0';
 }
Exemple #2
0
 /**
  * nggGallery::get_thumbnail_folder()
  *
  * @param mixed $gallerypath
  * @param bool $include_Abspath
  * @return string $foldername
  */
 static function create_thumbnail_folder($gallerypath, $include_Abspath = TRUE)
 {
     if (!$include_Abspath) {
         $gallerypath = ABSPATH . $gallerypath;
     }
     if (!file_exists($gallerypath)) {
         return FALSE;
     }
     if (is_dir($gallerypath . '/thumbs/')) {
         return '/thumbs/';
     }
     if (is_admin()) {
         if (!is_dir($gallerypath . '/thumbs/')) {
             if (!wp_mkdir_p($gallerypath . '/thumbs/')) {
                 if (SAFE_MODE) {
                     nggAdmin::check_safemode($gallerypath . '/thumbs/');
                 } else {
                     nggGallery::show_error(__('Unable to create directory ', 'nggallery') . $gallerypath . '/thumbs !');
                 }
                 return FALSE;
             }
             return '/thumbs/';
         }
     }
     return FALSE;
 }
Exemple #3
0
 /**
  * Upload function will be called via the Flash uploader
  *
  * @class nggAdmin
  * @param integer $galleryID
  * @return string $result
  */
 static function swfupload_image($galleryID = 0)
 {
     global $nggdb;
     if ($galleryID == 0) {
         return __('No gallery selected !', 'nggallery');
     }
     // WPMU action
     if (nggWPMU::check_quota()) {
         return '0';
     }
     // Check the upload
     if (!isset($_FILES['Filedata']) || !is_uploaded_file($_FILES['Filedata']['tmp_name']) || $_FILES['Filedata']['error'] != 0) {
         return __('Invalid upload. Error Code : ', 'nggallery') . $_FILES['Filedata']['error'];
     }
     // get the filename and extension
     $temp_file = $_FILES['Filedata']['tmp_name'];
     $filepart = nggGallery::fileinfo($_FILES['Filedata']['name']);
     $filename = $filepart['basename'];
     // check for allowed extension
     $ext = apply_filters('ngg_allowed_file_types', array('jpeg', 'jpg', 'png', 'gif'));
     if (!in_array(strtolower($filepart['extension']), $ext)) {
         return esc_html($_FILES[$key]['name']) . __('is no valid image file!', 'nggallery');
     }
     // get the path to the gallery
     $gallery = $nggdb->find_gallery((int) $galleryID);
     if (empty($gallery->path)) {
         @unlink($temp_file);
         return __('Failure in database, no gallery path set !', 'nggallery');
     }
     // read list of images
     $imageslist = nggAdmin::scandir(WINABSPATH . $gallery->path);
     // check if this filename already exist
     $i = 0;
     while (in_array($filename, $imageslist)) {
         $filename = $filepart['filename'] . '_' . $i++ . '.' . $filepart['extension'];
     }
     $dest_file = WINABSPATH . $gallery->path . '/' . $filename;
     // save temp file to gallery
     if (!@move_uploaded_file($_FILES["Filedata"]['tmp_name'], $dest_file)) {
         nggAdmin::check_safemode(WINABSPATH . $gallery->path);
         return __('Error, the file could not be moved to : ', 'nggallery') . esc_html($dest_file);
     }
     if (!nggAdmin::chmod($dest_file)) {
         return __('Error, the file permissions could not be set', 'nggallery');
     }
     return '0';
 }