当前位置: 首页>>代码示例>>PHP>>正文


PHP Safe::chmod方法代码示例

本文整理汇总了PHP中Safe::chmod方法的典型用法代码示例。如果您正苦于以下问题:PHP Safe::chmod方法的具体用法?PHP Safe::chmod怎么用?PHP Safe::chmod使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Safe的用法示例。


在下文中一共展示了Safe::chmod方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: shrink

 /**
  * create a thumbnail
  *
  * @param string the full path to the original file
  * @param string the pull path to write the thumbnail
  * @param boolean TRUE to resize to 60x60
  * @param boolean TRUE to see error messages, if any
  * @return TRUE on success, FALSE on error
  */
 public static function shrink($original, $target, $fixed = FALSE, $verbose = TRUE)
 {
     global $context;
     $file_name = basename($original);
     $open = Image::open($original);
     if ($open === FALSE) {
         return FALSE;
     }
     list($image, $image_information) = $open;
     // actual width
     $width = $image_information[0];
     // standard width
     if ($fixed) {
         $maximum_width = 60;
     } elseif (isset($context['thumbnail_width']) && $context['thumbnail_width'] >= 32) {
         $maximum_width = $context['thumbnail_width'];
     } else {
         $maximum_width = 60;
     }
     // actual height
     $height = $image_information[1];
     // standard height
     if ($fixed) {
         $maximum_height = 60;
     } elseif (isset($context['thumbnail_height']) && $context['thumbnail_height'] >= 32) {
         $maximum_height = $context['thumbnail_height'];
     } else {
         $maximum_height = 60;
     }
     // assume resize is not necessary
     $thumbnail_height = $height;
     $thumbnail_width = $width;
     // the image is laid vertically
     if ($height > $width) {
         // set the thumbnail size
         if ($height > $maximum_height) {
             $thumbnail_height = $maximum_height;
             $thumbnail_width = $width * $thumbnail_height / $height;
         }
         // the image is laid horizontally
     } else {
         // set the thumbnail size
         if ($width > $maximum_width) {
             $thumbnail_width = $maximum_width;
             $thumbnail_height = $height * $thumbnail_width / $width;
         }
     }
     // create target folder for the thumbnail
     if ($target_path = dirname($target)) {
         Safe::make_path($target_path);
     }
     // we already have a small image
     if ($thumbnail_width == $width && $thumbnail_height == $height) {
         // copy file content to the thumbnail
         if (!copy($original, $target)) {
             if ($verbose) {
                 Logger::error(sprintf(i18n::s('Cannot copy image to %s'), $target));
             }
             return FALSE;
         }
         // this will be filtered by umask anyway
         Safe::chmod($target, $context['file_mask']);
         // job done
         return TRUE;
     }
     // create the thumbnail in memory
     $thumbnail = NULL;
     if (Image::use_magic()) {
         $thumbnail = $image->resizeImage($thumbnail_width, $thumbnail_height, Imagick::FILTER_POINT, 1);
     } else {
         if ($image_information[2] == 2 && is_callable('ImageCreateTrueColor') && ($thumbnail = ImageCreateTrueColor($thumbnail_width, $thumbnail_height))) {
             ImageCopyResampled($thumbnail, $image, 0, 0, 0, 0, $thumbnail_width, $thumbnail_height, $width, $height);
         }
         if (!$thumbnail && is_callable('ImageCreate') && ($thumbnail = ImageCreate($thumbnail_width, $thumbnail_height))) {
             ImageCopyResized($thumbnail, $image, 0, 0, 0, 0, $thumbnail_width, $thumbnail_height, $width, $height);
         }
     }
     // sanity check
     if (!$thumbnail) {
         if ($verbose) {
             Logger::error(sprintf(i18n::s('Impossible to skrink image %s'), $file_name));
         }
         return FALSE;
     }
     // save the thumbnail in the file system
     $result = FALSE;
     if (Image::use_magic()) {
         $result = $image->writeImage($target);
     } else {
         if ($image_information[2] == 1 && is_callable('ImageGIF')) {
             ImageGIF($thumbnail, $target);
//.........这里部分代码省略.........
开发者ID:rair,项目名称:yacs,代码行数:101,代码来源:image.php

示例2: elseif

} elseif (isset($_REQUEST['action']) && $_REQUEST['action'] == 'confirm') {
    // list running scripts
    $context['text'] .= '<p>' . i18n::s('Listing files...') . BR . "\n";
    // locate script files starting at root
    $scripts = Scripts::list_scripts_at(NULL);
    if (is_array($scripts)) {
        $context['text'] .= BR . sprintf(i18n::s('%d scripts have been found.'), count($scripts)) . "\n";
    }
    $context['text'] .= "</p>\n";
    // chmod each file
    $context['text'] .= '<p>' . i18n::s('Updating file permissions...') . BR . "\n";
    // analyse each script
    $count = 0;
    foreach ($scripts as $file) {
        // this will be filtered by umask anyway
        Safe::chmod($context['path_to_root'] . $file, $context['file_mask']);
        $count++;
        // avoid timeouts
        if (!($count % 50)) {
            Safe::set_time_limit(30);
            SQL::ping();
        }
    }
    if ($count) {
        $context['text'] .= sprintf(i18n::s('%d files have been updated.'), $count) . "\n";
    }
    $context['text'] .= "</p>\n";
    // display the execution time
    $time = round(get_micro_time() - $context['start_time'], 2);
    $context['text'] .= '<p>' . sprintf(i18n::s('Script terminated in %.2f seconds.'), $time) . '</p>';
    // forward to the index page
开发者ID:rair,项目名称:yacs,代码行数:31,代码来源:chmod.php

示例3: upload


//.........这里部分代码省略.........
                 // check files extracted from the archive file
                 function explode_callback($name)
                 {
                     global $context;
                     // reject all files put in sub-folders
                     if (($path = substr($name, strlen($context['uploaded_path'] . '/'))) && strpos($path, '/') !== FALSE) {
                         Safe::unlink($name);
                     } elseif (!Files::is_authorized($name)) {
                         Safe::unlink($name);
                     } else {
                         // make it easy to download
                         $ascii = utf8::to_ascii(basename($name));
                         Safe::rename($name, $context['uploaded_path'] . '/' . $ascii);
                         // remember this name
                         $context['uploaded_files'][] = $ascii;
                     }
                 }
                 // extract archive components and save them in mentioned directory
                 $context['uploaded_files'] = array();
                 $context['uploaded_path'] = $file_path;
                 if (!($count = $zipfile->explode($context['path_to_root'] . $file_path . '/' . $file_name, $file_path, '', 'explode_callback'))) {
                     Logger::error(sprintf('Nothing has been extracted from %s.', $file_name));
                     return FALSE;
                 }
                 // one single file has been uploaded
             } else {
                 $context['uploaded_files'] = array($file_name);
             }
             // ensure we know the surfer
             Surfer::check_default_editor($_REQUEST);
             // post-process all uploaded files
             foreach ($context['uploaded_files'] as $file_name) {
                 // this will be filtered by umask anyway
                 Safe::chmod($context['path_to_root'] . $file_path . $file_name, $context['file_mask']);
                 // invoke post-processing function
                 if ($target && is_callable($target)) {
                     call_user_func($target, $file_name, $context['path_to_root'] . $file_path);
                     // we have to update an anchor page
                 } elseif ($target && is_string($target)) {
                     $fields = array();
                     // update a file with the same name for this anchor
                     if ($matching =& Files::get_by_anchor_and_name($target, $file_name)) {
                         $fields['id'] = $matching['id'];
                     } elseif (isset($input['id']) && ($matching = Files::get($input['id']))) {
                         $fields['id'] = $matching['id'];
                         // silently delete the previous version of the file
                         if (isset($matching['file_name'])) {
                             Safe::unlink($file_path . '/' . $matching['file_name']);
                         }
                     }
                     // prepare file record
                     $fields['file_name'] = $file_name;
                     $fields['file_size'] = filesize($context['path_to_root'] . $file_path . $file_name);
                     $fields['file_href'] = '';
                     $fields['anchor'] = $target;
                     // change title
                     if (isset($_REQUEST['title'])) {
                         $fields['title'] = $_REQUEST['title'];
                     }
                     // change has been documented
                     if (!isset($_REQUEST['version']) || !$_REQUEST['version']) {
                         $_REQUEST['version'] = '';
                     } else {
                         $_REQUEST['version'] = ' - ' . $_REQUEST['version'];
                     }
                     // always remember file uploads, for traceability
开发者ID:rair,项目名称:yacs,代码行数:67,代码来源:files.php

示例4: duplicate_for_anchor

 /**
  * duplicate all images for a given anchor
  *
  * This function duplicates records in the database, and changes anchors
  * to attach new records as per second parameter.
  *
  * @param string the source anchor
  * @param string the target anchor
  * @return int the number of duplicated records
  *
  * @see shared/anchors.php
  */
 public static function duplicate_for_anchor($anchor_from, $anchor_to)
 {
     global $context;
     // look for records attached to this anchor
     $count = 0;
     $query = "SELECT * FROM " . SQL::table_name('images') . " WHERE anchor LIKE '" . SQL::escape($anchor_from) . "'";
     if (($result = SQL::query($query)) && SQL::count($result)) {
         // create target folders
         $file_to = $context['path_to_root'] . Files::get_path($item['anchor'], 'images');
         if (!Safe::make_path($file_to . '/thumbs')) {
             Logger::error(sprintf(i18n::s('Impossible to create path %s.'), $file_to . '/thumbs'));
         }
         $file_to = $context['path_to_root'] . $file_to . '/';
         // the list of transcoded strings
         $transcoded = array();
         // process all matching records one at a time
         $file_from = $context['path_to_root'] . Files::get_path($anchor_from, 'images');
         while ($item = SQL::fetch($result)) {
             // sanity check
             if (!file_exists($context['path_to_root'] . $file_from . '/' . $item['image_name'])) {
                 continue;
             }
             // duplicate image file
             if (!copy($context['path_to_root'] . $file_from . '/' . $item['image_name'], $file_to . $item['image_name'])) {
                 Logger::error(sprintf(i18n::s('Impossible to copy file %s.'), $item['image_name']));
                 continue;
             }
             // this will be filtered by umask anyway
             Safe::chmod($file_to . $item['image_name'], $context['file_mask']);
             // copy the thumbnail as well
             Safe::copy($context['path_to_root'] . $file_from . '/' . $item['thumbnail_name'], $file_to . $item['thumbnail_name']);
             // this will be filtered by umask anyway
             Safe::chmod($file_to . $item['thumbnail_name'], $context['file_mask']);
             // a new id will be allocated
             $old_id = $item['id'];
             unset($item['id']);
             // target anchor
             $item['anchor'] = $anchor_to;
             // actual duplication
             if ($new_id = Images::post($item)) {
                 // more pairs of strings to transcode --no automatic solution for [images=...]
                 $transcoded[] = array('/\\[image=' . preg_quote($old_id, '/') . '/i', '[image=' . $new_id);
                 // duplicate elements related to this item
                 Anchors::duplicate_related_to('image:' . $old_id, 'image:' . $new_id);
                 // stats
                 $count++;
             }
         }
         // transcode in anchor
         if ($anchor = Anchors::get($anchor_to)) {
             $anchor->transcode($transcoded);
         }
     }
     // number of duplicated records
     return $count;
 }
开发者ID:rair,项目名称:yacs,代码行数:68,代码来源:images.php

示例5: array

         continue;
     }
     // store the footprint for later use --number of lines, content hash
     $footprints[$file] = array($footprint[0], $footprint[1]);
     // ensure a clean reference store
     Safe::unlink($context['path_to_reference'] . $file);
     // create adequate path
     if (!Safe::make_path($context['path_to_reference'] . dirname($file))) {
         $context['text'] .= sprintf(i18n::s('Impossible to create path %s.'), $context['path_to_reference'] . dirname($file)) . BR . "\n";
     } elseif (!Safe::copy($context['path_to_root'] . $file, $context['path_to_reference'] . $file)) {
         $context['text'] .= sprintf(i18n::s('Impossible to copy file %s.'), $file) . BR . "\n";
     } else {
         // try to preserve the modification date
         Safe::touch($context['path_to_reference'] . $file, Safe::filemtime($context['path_to_root'] . $file));
         // this will be filtered by umask anyway
         Safe::chmod($context['path_to_reference'] . $file, $context['file_mask']);
     }
     // avoid timeouts
     if (!(count($footprints) % 50)) {
         Safe::set_time_limit(30);
         SQL::ping();
     }
 }
 if (count($footprints)) {
     $context['text'] .= sprintf(i18n::s('%d reference scripts have been copied.'), count($footprints)) . "\n";
 }
 $context['text'] .= "</p>\n";
 // purge documentation pages
 $context['text'] .= '<p>' . i18n::s('Purging the documentation pages...') . "</p>\n";
 // get a parser
 include_once 'phpdoc.php';
开发者ID:rair,项目名称:yacs,代码行数:31,代码来源:build.php

示例6: _extractList


//.........这里部分代码省略.........
         } else {
             $v_extract_file = TRUE;
         }
         // ----- Look if this file need to be extracted
         if ($v_extract_file && !$v_listing) {
             if ($p_remove_path != '' && substr($v_header['filename'], 0, $p_remove_path_size) == $p_remove_path) {
                 $v_header['filename'] = substr($v_header['filename'], $p_remove_path_size);
             }
             if ($p_path != './' && $p_path != '/') {
                 while (substr($p_path, -1) == '/') {
                     $p_path = substr($p_path, 0, strlen($p_path) - 1);
                 }
                 if (substr($v_header['filename'], 0, 1) == '/') {
                     $v_header['filename'] = $p_path . $v_header['filename'];
                 } else {
                     $v_header['filename'] = $p_path . '/' . $v_header['filename'];
                 }
             }
             if (file_exists($v_header['filename'])) {
                 if (@is_dir($v_header['filename']) && $v_header['typeflag'] == '') {
                     $this->_error('File ' . $v_header['filename'] . ' already exists as a directory');
                     return false;
                 }
                 if ($this->_isArchive($v_header['filename']) && $v_header['typeflag'] == "5") {
                     $this->_error('Directory ' . $v_header['filename'] . ' already exists as a file');
                     return false;
                 }
                 if (!is_writeable($v_header['filename'])) {
                     $this->_error('File ' . $v_header['filename'] . ' already exists and is write protected');
                     return false;
                 }
                 if (filemtime($v_header['filename']) > $v_header['mtime']) {
                     // To be completed : An error or silent no replace ?
                 }
             } elseif (($v_result = $this->_dirCheck($v_header['typeflag'] == "5" ? $v_header['filename'] : dirname($v_header['filename']))) != 1) {
                 $this->_error('Unable to create path for ' . $v_header['filename']);
                 return false;
             }
             if ($v_extract_file) {
                 if ($v_header['typeflag'] == "5") {
                     if (!@file_exists($v_header['filename'])) {
                         global $context;
                         if (!@mkdir($v_header['filename'], $context['directory_mask'])) {
                             $this->_error('Unable to create directory {' . $v_header['filename'] . '}');
                             return false;
                         }
                     }
                 } else {
                     if (($v_dest_file = @fopen($v_header['filename'], "wb")) == 0) {
                         $this->_error('Error while opening {' . $v_header['filename'] . '} in write binary mode');
                         return false;
                     } else {
                         $n = floor($v_header['size'] / 512);
                         for ($i = 0; $i < $n; $i++) {
                             $v_content = $this->_readBlock();
                             fwrite($v_dest_file, $v_content, 512);
                         }
                         if ($v_header['size'] % 512 != 0) {
                             $v_content = $this->_readBlock();
                             fwrite($v_dest_file, $v_content, $v_header['size'] % 512);
                         }
                         @fclose($v_dest_file);
                         // ----- Change the file mode, mtime
                         @touch($v_header['filename'], $v_header['mtime']);
                         // To be completed
                         Safe::chmod($v_header['filename']);
                     }
                     // ----- Check the file size
                     clearstatcache();
                     if (filesize($v_header['filename']) != $v_header['size']) {
                         $this->_error('Extracted file ' . $v_header['filename'] . ' does not have the correct file size \'' . filesize($v_header['filename']) . '\' (' . $v_header['size'] . ' expected). Archive may be corrupted.');
                         return false;
                     }
                 }
             } else {
                 $this->_jumpBlock(ceil($v_header['size'] / 512));
             }
         } else {
             $this->_jumpBlock(ceil($v_header['size'] / 512));
         }
         /* TBC : Seems to be unused ...
         	  if ($this->_compress)
         		$v_end_of_file = @gzeof($this->_file);
         	  else
         		$v_end_of_file = @feof($this->_file);
         		*/
         if ($v_listing || $v_extract_file || $v_extraction_stopped) {
             // ----- Log extracted files
             if (($v_file_dir = dirname($v_header['filename'])) == $v_header['filename']) {
                 $v_file_dir = '';
             }
             if (substr($v_header['filename'], 0, 1) == '/' && $v_file_dir == '') {
                 $v_file_dir = '/';
             }
             $p_list_detail[$v_nb++] = $v_header;
         }
         Safe::set_time_limit(30);
     }
     return true;
 }
开发者ID:rair,项目名称:yacs,代码行数:101,代码来源:tar.php

示例7: elseif

         continue;
     }
 }
 // we should have an updated file in the staging directory
 if (file_exists($context['path_to_root'] . 'scripts/staging/' . $file)) {
     // we don't care about missing run-once scripts
 } elseif (preg_match('/\\brun_once\\b/i', $file)) {
     continue;
     // report on the missing file
 } else {
     $context['text'] .= sprintf(i18n::s('ERROR: File %s is missing or corrupted.'), $file) . BR . "\n";
     $missing_files++;
     continue;
 }
 // this will be filtered by umask anyway
 Safe::chmod($context['path_to_root'] . 'scripts/staging/' . $file, $context['file_mask']);
 // maybe we have to update the front page
 if ($file == 'index.php' && isset($context['home_at_root']) && $context['home_at_root'] == 'Y') {
     if (Safe::copy($context['path_to_root'] . 'scripts/staging/index.php', $context['path_to_root'] . '../index.php')) {
         $context['text'] .= sprintf(i18n::s('%s has been updated'), '../index.php') . ' (' . $attributes[0] . ' ' . i18n::s('lines') . ')' . BR . "\n";
         $updated_files++;
         // failed update
     } else {
         $context['text'] .= FAILURE_PREFIX . sprintf(i18n::s('Impossible to write to %s.'), '../index.php') . FAILURE_SUFFIX . BR . "\n";
         $failures++;
     }
 }
 // ensure all folders exist
 if (!Safe::make_path(dirname($file))) {
     $context['text'] .= FAILURE_PREFIX . sprintf(i18n::s('Impossible to create path %s.'), dirname($file)) . FAILURE_SUFFIX . BR . "\n";
     $failures++;
开发者ID:rair,项目名称:yacs,代码行数:31,代码来源:update.php


注:本文中的Safe::chmod方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。