示例#1
0
 public function __construct($location)
 {
     $this->location = $location;
     if (!is_dir($this->location)) {
         mkdir($this->location, awpcp_directory_permissions(), true);
     }
 }
示例#2
0
 private function write_uploaded_data_to_file($file_path)
 {
     $base_dir = dirname($file_path);
     if (!file_exists($base_dir) && !mkdir($base_dir, awpcp_directory_permissions(), true)) {
         throw new AWPCP_Exception(__("Temporary directory doesn't exists and couldn't be created.", 'AWPCP'));
     }
     if (!empty($_FILES) && isset($_FILES['file'])) {
         if ($_FILES['file']['error']) {
             list($error_code, $error_message) = awpcp_uploaded_file_error($_FILES['file']);
             throw new AWPCP_Exception($error_message);
         }
         if (!is_uploaded_file($_FILES['file']['tmp_name'])) {
             throw new AWPCP_Exception(__('There was an error trying to move the uploaded file to a temporary location.', 'AWPCP'));
         }
         move_uploaded_file($_FILES['file']['tmp_name'], $file_path);
     } else {
         if (!($input = fopen('php://input', 'rb'))) {
             throw new AWPCP_Exception(__("There was an error trying to open PHP's input stream.", 'AWPCP'));
         }
         if (!($output = fopen($file_path, 'wb'))) {
             throw new AWPCP_Exception(__('There was an error trying to open the output stream.', 'AWPCP'));
         }
         while ($buffer = fread($input, 4096)) {
             fwrite($output, $buffer);
         }
         fclose($output);
         fclose($input);
     }
 }
 private function make_intermediate_image_size($file, $destination_dir, $width, $height, $crop = false, $suffix = '')
 {
     if (!file_exists($destination_dir) && !mkdir($destination_dir, awpcp_directory_permissions(), true)) {
         throw new AWPCP_Exception(__("Destination directory doesn't exists and couldn't be created.", 'AWPCP'));
     }
     $image = image_make_intermediate_size($file->get_path(), $width, $height, $crop);
     $safe_suffix = empty($suffix) ? '.' : "-{$suffix}.";
     $image_name = $file->get_file_name() . $safe_suffix . $file->get_extension();
     $image_path = implode(DIRECTORY_SEPARATOR, array($destination_dir, $image_name));
     if (is_array($image)) {
         $source_path = implode(DIRECTORY_SEPARATOR, array($file->get_parent_directory(), $image['file']));
         $result = rename($source_path, $image_path);
     }
     if (!isset($result) || $result === false) {
         $result = copy($file->get_path(), $image_path);
     }
     chmod($image_path, 0644);
     return $result;
 }
 public function move_file_to($file, $relative_path, $related_directories = array())
 {
     $destination_dir = $this->get_path_for_relative_path($relative_path);
     if (!file_exists($destination_dir) && !mkdir($destination_dir, awpcp_directory_permissions(), true)) {
         throw new AWPCP_Exception(__("Destination directory doesn't exists and couldn't be created.", 'AWPCP'));
     }
     $target_directories = array_merge(array($destination_dir), $related_directories);
     $unique_filename = awpcp_unique_filename($file->get_path(), $file->get_real_name(), $target_directories);
     $destination_path = implode(DIRECTORY_SEPARATOR, array($destination_dir, $unique_filename));
     if (rename($file->get_path(), $destination_path)) {
         $file->set_path($destination_path);
         chmod($destination_path, 0644);
     } else {
         unlink($file->get_path());
         $message = _x('The file %s could not be copied to the destination directory.', 'upload files', 'AWPCP');
         $message = sprintf($message, $file->get_real_name());
         throw new AWPCP_Exception($message);
     }
     return $file;
 }
示例#5
0
/**
 * Verifies the upload directories exists and have proper permissions, then
 * returns the path to the directories to store raw files and image thumbnails.
 *
 * @since 3.0.2
 * @deprecated 3.4
 */
function awpcp_get_uploads_directories()
{
    static $uploads_directories = null;
    if (is_null($uploads_directories)) {
        global $wpcontentdir;
        $permissions = awpcp_directory_permissions();
        $upload_dir_name = get_awpcp_option('uploadfoldername', 'uploads');
        $upload_dir = $wpcontentdir . '/' . $upload_dir_name . '/';
        // Required to set permission on main upload directory
        require_once AWPCP_DIR . '/fileop.class.php';
        $fileop = new fileop();
        $owner = fileowner($wpcontentdir);
        if (!is_dir($upload_dir) && is_writable($wpcontentdir)) {
            umask(0);
            mkdir($upload_dir, $permissions);
            chown($upload_dir, $owner);
        }
        $fileop->set_permission($upload_dir, $permissions);
        $files_dir = $upload_dir . 'awpcp/';
        $thumbs_dir = $upload_dir . 'awpcp/thumbs/';
        if (!is_dir($files_dir) && is_writable($upload_dir)) {
            umask(0);
            @mkdir($files_dir, $permissions);
            @chown($files_dir, $owner);
        }
        if (!is_dir($thumbs_dir) && is_writable($upload_dir)) {
            umask(0);
            @mkdir($thumbs_dir, $permissions);
            @chown($thumbs_dir, $owner);
        }
        $fileop->set_permission($files_dir, $permissions);
        $fileop->set_permission($thumbs_dir, $permissions);
        $uploads_directories = array('files_dir' => $files_dir, 'thumbnails_dir' => $thumbs_dir);
    }
    return $uploads_directories;
}
示例#6
0
/**
 * XXX: Moved to ImageFileProcessor class.
 */
function awpcp_make_intermediate_size($file, $directory, $width, $height, $crop = false, $suffix = '')
{
    $path_info = awpcp_utf8_pathinfo($file);
    $filename = preg_replace("/\\.{$path_info['extension']}/", '', $path_info['basename']);
    $suffix = empty($suffix) ? '.' : "-{$suffix}.";
    $newpath = trailingslashit($directory) . $filename . $suffix . $path_info['extension'];
    $image = image_make_intermediate_size($file, $width, $height, $crop);
    if (!is_writable($directory)) {
        @chmod($directory, awpcp_directory_permissions());
    }
    if (is_array($image) && !empty($image)) {
        $tmppath = trailingslashit($path_info['dirname']) . $image['file'];
        $result = rename($tmppath, $newpath);
    } else {
        $result = copy($file, $newpath);
    }
    @chmod($newpath, 0644);
    return $result;
}
示例#7
0
 public function unzip($file, &$errors = array())
 {
     if (!file_exists($file)) {
         $message = __('File %s does not exists.', 'AWPCP');
         $errors[] = sprintf($message, $file);
         return false;
     }
     $import_dir = $this->prepare_import_dir();
     if (false === $import_dir) {
         $message = __('Import directory %s does not exists.', 'AWPCP');
         $errors[] = sprintf($message, $import_dir);
         return false;
     }
     require_once ABSPATH . 'wp-admin/includes/class-pclzip.php';
     $archive = new PclZip($file);
     $items = $archive->extract(PCLZIP_OPT_EXTRACT_AS_STRING);
     $files = array();
     if (!is_array($items)) {
         $errors[] = __('Incompatible ZIP Archive', 'AWPCP');
         return false;
     }
     if (0 === count($items)) {
         $errors[] = __('Empty ZIP Archive', 'AWPCP');
         return false;
     }
     foreach ($items as $item) {
         // ignore folder and don't extract the OS X-created __MACOSX directory files
         if ($item['folder'] || '__MACOSX/' === substr($item['filename'], 0, 9)) {
             continue;
         }
         // don't extract files with a filename starting with . (like .DS_Store)
         if ('.' === substr(basename($item['filename']), 0, 1)) {
             continue;
         }
         $path = trailingslashit($import_dir) . $item['filename'];
         // if file is inside a directory, create it first
         if (dirname($item['filename']) !== '.') {
             @mkdir($import_dir . '/' . dirname($item['filename']), awpcp_directory_permissions(), true);
         }
         // extract file
         if ($h = @fopen($path, 'w')) {
             fwrite($h, $item['content']);
             fclose($h);
         } else {
             $message = __('Could not write temporary file %s', 'AWPCP');
             $errors[] = sprintf($message, $path);
         }
         if (file_exists($path)) {
             $files[] = array('path' => $path, 'filename' => $item['filename']);
         }
     }
     return $files;
 }