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


PHP filesystem::is_writable方法代码示例

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


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

示例1: upload

 private function upload($tmpfile, $shortname, $description = '', $replace = false)
 {
     try {
         $audioInfo = MediaScanner::getAudioInfo($tmpfile);
     } catch (Exception $e) {
         message::set('File error: ' . $e->getMessage());
         return FALSE;
     }
     $destfile = Media::getMediaFilename($shortname, $audioInfo['rates'][0], FALSE);
     // Get whatever the proper name should be
     $dir = dirname($destfile);
     /* can we write to the target folder? */
     if (!filesystem::is_writable($dir)) {
         message::set('The path ' . $dir . ' is not writable!');
         return FALSE;
     }
     $this->createFolder($dir);
     if (!is_writable(dirname($destfile)) or file_exists($destfile) and !is_writable($destfile)) {
         message::set(dirname($destfile) . ' is not writable');
         return FALSE;
     }
     try {
         move_uploaded_file($tmpfile, $destfile);
     } catch (Exception $e) {
         message::set('Unable to move uploaded file into ' . $destfile . '. ' . $e->getMessage());
         return FALSE;
     }
     // See if this is in the DB
     $mediaFile = Doctrine::getTable('MediaFile')->findOneByFile($shortname);
     if ($mediaFile) {
         // Note that this is a bit dangerous and could use improvement.
         // We assume that all other properties in the file we just found match the file already uploaded.
         // That means if someone uploads the wrong audio file, it kinda messes things up big time.
         if (!in_array($audioInfo['byterate'], (array) $mediaFile['registry']['rates'])) {
             Kohana::log('debug', 'Updating ' . $shortname . "...");
             $registry = (array) $mediaFile['registry'];
             $registry['rates'][] = $audioInfo['byterate'];
             $mediaFile['registry'] = $registry;
             $mediaFile['description'] = strlen($description) > 0 ? $description : $mediaFile['description'];
             $mediaFile->save();
         } else {
             if (strcmp($mediaFile['description'], $description)) {
                 $mediaFile['description'] = $description;
                 $mediaFile->save();
             } else {
                 Kohana::log('debug', 'SKIPPED DB UPDATE - Nothing to update on ' . $shortname . " with sample rate " . $audioInfo['byterate'] . "... ");
             }
         }
         message::set('Successfully updated audio file in the system.', 'success');
         url::redirect(Router_Core::$controller . '/index');
     } else {
         // NEW FILE! Do lots of stuff
         // Save info about file
         $mediaFile = new MediaFile();
         $mediaFile['file'] = $shortname;
         $mediaFile['path'] = dirname($mediaFile['file']);
         // We track the path separately to ease searching
         $mediaFile['account_id'] = 1;
         // See if we know this filename, description & category from the XML info
         if (isset($descriptions[$shortname])) {
             $mediaFile['description'] = $descriptions[$shortname];
         } else {
             if (strlen($description) > 0) {
                 $mediaFile['description'] = $description;
             } else {
                 $mediaFile['description'] = 'Unknown';
             }
         }
         Kohana::log('debug', 'Adding ' . $mediaFile['file'] . " to the database.");
         $mediaFile['registry'] += $audioInfo;
         $mediaFile->save();
         message::set('Successfully added audio file to the system.', 'success');
         url::redirect(Router_Core::$controller . '/index');
     }
 }
开发者ID:swk,项目名称:bluebox,代码行数:75,代码来源:globalmedia.php

示例2: _checkDirPermissions

 /**
  * Ensures the logs and cache directory have write permissions
  *
  * TODO: Consider checking perissions on FreeSwitch conf but it may be too early here.....hmmmm
  *
  * @return results array
  */
 private function _checkDirPermissions()
 {
     $testDirectories = array('/bluebox/cache/', '/bluebox/logs/');
     $result = array('name' => __('Directory Permissions'), 'fail_msg' => __('The following directories do not have write permissions') . ':<ul>', 'pass_msg' => __('Pass'), 'result' => TRUE, 'required' => TRUE);
     foreach ($testDirectories as $testDirectory) {
         $dir = getcwd() . $testDirectory;
         if (!filesystem::is_writable($dir)) {
             $result['fail_msg'] .= '<li>' . ltrim($testDirectory, '/') . '</li>';
             $result['result'] = FALSE;
         }
     }
     $result['fail_msg'] .= '</ul>';
     return $result;
 }
开发者ID:swk,项目名称:bluebox,代码行数:21,代码来源:installer.php

示例3: prepare_upload

 public function prepare_upload($uploadvar = 'upload')
 {
     if (!arr::get($_FILES, 'mediafile', 'name', $uploadvar)) {
         kohana::log('error', 'Attempted to prepare upload without file');
         return 'Please provide a file to upload';
     }
     $uploadedFile = arr::get(arr::rotate($_FILES['mediafile']), $uploadvar);
     switch ($uploadedFile['error']) {
         case UPLOAD_ERR_INI_SIZE:
             return 'File exceeds upload_max_filesize';
         case UPLOAD_ERR_FORM_SIZE:
             return 'File exceeds MAX_FILE_SIZE';
         case UPLOAD_ERR_PARTIAL:
             return 'File was only partially uploaded';
         case UPLOAD_ERR_NO_FILE:
             return 'No file was uploaded';
         case UPLOAD_ERR_NO_TMP_DIR:
             return 'Missing a temporary folder';
         case UPLOAD_ERR_CANT_WRITE:
             return 'Failed to write file to disk';
         case UPLOAD_ERR_EXTENSION:
             return 'Invalid file extension (type)';
         case UPLOAD_ERR_OK:
             if (!$this->get('file')) {
                 $uploadFilename = $uploadedFile['name'];
                 if (Kohana::config('upload.remove_spaces') === TRUE) {
                     $uploadFilename = preg_replace('/\\s+/', '_', $uploadFilename);
                 }
                 $this->set('file', $uploadFilename);
             }
             if ($this->get('path')) {
                 $path = trim($this->get('path'), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
                 $this->set('path', $path);
             }
             if (!is_file($uploadedFile['tmp_name'])) {
                 kohana::log('error', 'Unable to locate file in temporary storage ' . $uploadedFile['tmp_name']);
                 return 'Unable to upload file';
             }
             if (!($mediainfo = MediaLib::getAudioInfo($uploadedFile['tmp_name']))) {
                 kohana::log('error', 'Unable to determine audio info for tmp upload file "' . $uploadedFile['tmp_name'] . '"');
                 return 'Upload is not a valid audio file or format';
             }
             $this->fromArray($mediainfo);
             if (kohana::config('mediafile.upload_to_rate_folders')) {
                 $rate = $this->get('rates');
                 $path = $this->get('path');
                 if (in_array($rate, kohana::config('mediafile.default_rates')) and !strstr($path, $rate . DIRECTORY_SEPARATOR)) {
                     $path .= $this->get('rates') . DIRECTORY_SEPARATOR;
                     $this->set('path', $path);
                 } else {
                     if ($unknownPath = kohana::config('mediafile.unknown_rate_folder')) {
                         $path .= trim($unknownPath, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
                         $this->set('path', $path);
                     }
                 }
             }
             $directory = $this->filepath();
             if (!$this->get('name') or !$this->get('description')) {
                 $mediafiles = $this->get_resampled();
                 if (!$this->get('name')) {
                     if (isset($mediafiles[0]['name'])) {
                         $this->set('name', $mediafiles[0]['name']);
                     } else {
                         $this->set('name', pathinfo($uploadedFile['name'], PATHINFO_FILENAME));
                     }
                 }
                 if (!$this->get('description')) {
                     if (isset($mediafiles[0]['description'])) {
                         $this->set('description', $mediafiles[0]['description']);
                     }
                 }
             }
             if (!$directory or !filesystem::is_writable($directory) and !filesystem::createDirectory($directory)) {
                 kohana::log('error', 'The configured media dir is not writable, please chmod "' . $directory . '"');
                 return 'Media collection directory is not writable';
             }
             $this->uploaded_file = $uploadedFile;
             break;
         default:
             return 'Upload failed for an unspecified reason';
     }
     return FALSE;
 }
开发者ID:swk,项目名称:bluebox,代码行数:83,代码来源:MediaFile.php

示例4: save

 public function save()
 {
     if (!class_exists('DOMDocument')) {
         message::set('This driver requires ' . html::anchor('http://us3.php.net/manual/en/class.domdocument.php', 'DOMDocument', array('target' => '_new')) . ' to be installed and active');
         return false;
     }
     // This array maps the telephony returns to the telephony file
     $telephonyOptions = array('cfg_root' => rtrim($this->session->get('installer.cfg_root'), '/'), 'audio_root' => rtrim($this->session->get('installer.audio_root'), '/'), 'ESLHost' => $this->session->get('installer.esl_host'), 'ESLPort' => $this->session->get('installer.esl_port'), 'ESLAuth' => $this->session->get('installer.esl_auth'));
     if (!is_dir($telephonyOptions['cfg_root'])) {
         message::set('Unable to access directory <pre>' . $telephonyOptions['cfg_root'] . '</pre>');
         return false;
     }
     if (!is_dir($telephonyOptions['audio_root'])) {
         message::set('Unable to access directory <pre>' . $telephonyOptions['audio_root'] . '</pre>');
         return false;
     }
     // Write $telephonyOptions to freeswitch.php
     if (!Installer_Controller::updateConfig($telephonyOptions, 'freeswitch')) {
         return false;
     }
     // Set the driver name in telephony.php
     if (!Installer_Controller::updateConfig(array('driver' => 'FreeSwitch'), 'telephony')) {
         return false;
     }
     // Reload the new telephony options so we can use the filemap
     Kohana::config_clear('freeswitch');
     Kohana::config_load('freeswitch');
     $filemaps = Kohana::config('freeswitch.filemap');
     $notWritable = array();
     foreach ($filemaps as $filemap) {
         if (!filesystem::is_writable($filemap['filename'])) {
             $notWritable[] = $filemap['filename'];
         }
     }
     if (!empty($notWritable)) {
         $notWritable = array_unique($notWritable);
         if (empty($this->template->error)) {
             message::set('Ensure the web server has write permission on these files, and SELINUX allows this action.' . '<div class="write_help">Unable to write to the following file(s):</div>' . '<div>' . arr::arrayToUL($notWritable, array(), array('class' => 'error_details', 'style' => 'text-align:left;')) . '</div>');
         }
         return false;
     }
     // Make sure that if the user changed the directory and any conflicts were found that the user
     // knows these will be deleted
     $existingProfiles = glob(rtrim($telephonyOptions['cfg_root'], '/') . '/sip_profiles/*.xml', GLOB_MARK);
     $oldXmlFiles = array();
     foreach ($filemaps as $filemap) {
         if (file_exists($filemap['filename'])) {
             $oldXmlFiles[] = $filemap['filename'];
         }
     }
     $conflictXmlFiles = $this->session->get('installer.conflictXmlFiles');
     foreach (array_unique(array_merge($existingProfiles, $oldXmlFiles)) as $existingFile) {
         if (!in_array($existingFile, $conflictXmlFiles)) {
             message::set('Conflicting configuration files will be permanently erased if you continue!');
             message::set('Click continue again to proceed...', 'alert');
             // This session var lets the user continue the second time around (after the warning)
             $this->session->set('installer.confirm_delete', true);
             return false;
         }
     }
     // If there are conflictXmlFile in the session then the user has seen this list
     // so they SHOULD be aware we are about to delete them... should
     $conflictXmlFiles = $this->session->get('installer.conflictXmlFiles');
     if (!empty($conflictXmlFiles) && is_array($conflictXmlFiles)) {
         $confirmDelete = $this->session->get('installer.confirm_delete', false);
         if (empty($confirmDelete)) {
             message::set('Conflicting configuration files will be permanently erased if you continue!');
             message::set('Click continue again to proceed...', 'alert');
             // This session var lets the user continue the second time around (after the warning)
             $this->session->set('installer.confirm_delete', true);
             return false;
         }
         foreach ($conflictXmlFiles as $conflictXmlFile) {
             if (!filesystem::delete($conflictXmlFile)) {
                 Kohana::log('error', 'Unable to unlink ' . $conflictXmlFile);
                 $unlinkErrors[] = $conflictXmlFile;
             }
         }
     }
     // If there are files that could not be deleted, inform the user
     if (!empty($unlinkErrors)) {
         message::set('Manually remove these files or change the file permissions.' . '<div class="write_help">Unable to delete incompatible file(s):</div>' . '<div>' . arr::arrayToUL($unlinkErrors, array(), array('class' => 'error_details', 'style' => 'text-align:left;')) . '</div>');
         return false;
     }
     $this->session->set('installer.default_packages', kohana::config('freeswitch.default_packages'));
     return true;
 }
开发者ID:swk,项目名称:bluebox,代码行数:87,代码来源:freeswitch.php


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