示例#1
0
 /**
  * Upload function will be called via the Flash uploader
  * 
  * @class flagAdmin
  * @param integer $galleryID
  * @return string $result
  */
 static function swfupload_image($galleryID = 0)
 {
     global $wpdb;
     if ($galleryID == 0) {
         //@unlink($temp_file);
         return __('No gallery selected!', 'flag');
     }
     // WPMU action
     if (flagAdmin::check_quota()) {
         return '0';
     }
     // Check the upload
     if (!isset($_FILES['file']) || !is_uploaded_file($_FILES["file"]["tmp_name"]) || $_FILES["file"]["error"] === UPLOAD_ERR_OK) {
         flagAdmin::file_upload_error_message($_FILES['file']['error']);
     }
     // get the filename and extension
     $temp_file = $_FILES["file"]['tmp_name'];
     $filepart = flagGallery::fileinfo($_FILES['file']['name']);
     $filename = $filepart['basename'];
     // check for allowed extension
     $ext = array('jpeg', 'jpg', 'png', 'gif');
     if (!in_array($filepart['extension'], $ext)) {
         return $filename . ' ' . __('is no valid image file!', 'flag');
     }
     // get the path to the gallery
     $gallerypath = $wpdb->get_var($wpdb->prepare("SELECT path FROM {$wpdb->flaggallery} WHERE gid = %d ", $galleryID));
     if (!$gallerypath) {
         @unlink($temp_file);
         return __('Failure in database, no gallery path set !', 'flag');
     }
     // read list of images
     $imageslist = flagAdmin::scandir(WINABSPATH . $gallerypath);
     // check if this filename already exist
     $i = 0;
     while (in_array($filename, $imageslist)) {
         $filename = sanitize_title($filepart['filename']) . '_' . $i++ . '.' . $filepart['extension'];
     }
     $dest_file = WINABSPATH . $gallerypath . '/' . $filename;
     // save temp file to gallery
     if (!@move_uploaded_file($temp_file, $dest_file)) {
         flagAdmin::check_safemode(WINABSPATH . $gallerypath);
         return __('Error, the file could not moved to : ', 'flag') . $dest_file;
     }
     if (!flagAdmin::chmod($dest_file)) {
         return __('Error, the file permissions could not set', 'flag');
     }
     // add images to database
     $image_ids = flagAdmin::add_Images($galleryID, array($filename));
     $return = '';
     //create thumbnails
     foreach ($image_ids as $picture) {
         $return = flagAdmin::create_thumbnail($picture);
     }
     //add the preview image if needed
     if (intval($_POST['last']) == 1) {
         flagAdmin::set_gallery_preview($galleryID);
     }
     return intval($return) == 1 ? '' : $return;
 }