本文整理汇总了PHP中Varien_Io_File::chmod方法的典型用法代码示例。如果您正苦于以下问题:PHP Varien_Io_File::chmod方法的具体用法?PHP Varien_Io_File::chmod怎么用?PHP Varien_Io_File::chmod使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Varien_Io_File
的用法示例。
在下文中一共展示了Varien_Io_File::chmod方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _loadFiles
protected function _loadFiles()
{
if (!$this->_isLoaded) {
$readPath = Mage::getBaseDir("var") . DS . "backups";
$ioProxy = new Varien_Io_File();
try {
$ioProxy->open(array('path' => $readPath));
} catch (Exception $e) {
$ioProxy->mkdir($readPath, 0755);
$ioProxy->chmod($readPath, 0755);
$ioProxy->open(array('path' => $readPath));
}
if (!is_file($readPath . DS . ".htaccess")) {
// Deny from reading in browser
$ioProxy->write(".htaccess", "deny from all", 0644);
}
$list = $ioProxy->ls(Varien_Io_File::GREP_FILES);
$fileExtension = constant($this->_itemObjectClass . "::BACKUP_EXTENSION");
foreach ($list as $entry) {
if ($entry['filetype'] == $fileExtension) {
$item = new $this->_itemObjectClass();
$item->load($entry['text'], $readPath);
if ($this->_checkCondition($item)) {
$this->addItem($item);
}
}
}
$this->_totalRecords = count($this->_items);
if ($this->_totalRecords > 1) {
usort($this->_items, array(&$this, 'compareByTypeOrDate'));
}
$this->_isLoaded = true;
}
return $this;
}
示例2: _createCopy
/**
* Copy current theme to specified file
*
* @param $filePath
* @return string new file
*/
protected function _createCopy($filePath)
{
$currentThemeFileName = $this->_getThemeFile();
$ioFile = new Varien_Io_File();
if (!$ioFile->cp($currentThemeFileName, $filePath)) {
Mage::throwException(Mage::helper('xmlconnect')->__('Can\'t copy file "%s" to "%s".', $currentThemeFileName, $filePath));
} else {
$ioFile->chmod($filePath, 0755);
}
return $filePath;
}
示例3: resetTheme
/**
* Reset themes color changes
* Copy /xmlconnect/etc/themes/* to media/xmlconnect/themes/*
*
* @throws Mage_Core_Exception
* @param null $theme
* @return null
*/
public function resetTheme($theme = null)
{
$themeDir = $this->getMediaThemePath();
$defaultThemeDir = $this->_getDefaultThemePath();
$ioFile = new Varien_Io_File();
$ioFile->open(array('path' => $defaultThemeDir));
$fileList = $ioFile->ls(Varien_Io_File::GREP_FILES);
foreach ($fileList as $file) {
$f = $file['text'];
$src = $defaultThemeDir . DS . $f;
$dst = $themeDir . DS . $f;
if ($theme && $theme . '.xml' != $f) {
continue;
}
if (!$ioFile->cp($src, $dst)) {
Mage::throwException(Mage::helper('xmlconnect')->__('Can\'t copy file "%s" to "%s".', $src, $dst));
} else {
$ioFile->chmod($dst, 0755);
}
}
}
示例4: addImage
/**
* Add image to media gallery and return new filename
*
* @param Mage_Catalog_Model_Product $product
* @param string $file file path of image in file system
* @param string|array $mediaAttribute code of attribute with type 'media_image',
* leave blank if image should be only in gallery
* @param boolean $move if true, it will move source file
* @param boolean $exclude mark image as disabled in product page view
* @return string
*/
public function addImage(Mage_Catalog_Model_Product $product, $file, $mediaAttribute = null, $move = false, $exclude = true)
{
$file = realpath($file);
if (!$file || !file_exists($file)) {
Mage::throwException(Mage::helper('catalog')->__('Image does not exist.'));
}
$pathinfo = pathinfo($file);
$imgExtensions = array('jpg', 'jpeg', 'gif', 'png');
if (!isset($pathinfo['extension']) || !in_array(strtolower($pathinfo['extension']), $imgExtensions)) {
Mage::throwException(Mage::helper('catalog')->__('Invalid image file type.'));
}
$fileName = Mage_Core_Model_File_Uploader::getCorrectFileName($pathinfo['basename']);
$dispretionPath = Mage_Core_Model_File_Uploader::getDispretionPath($fileName);
$fileName = $dispretionPath . DS . $fileName;
$fileName = $this->_getNotDuplicatedFilename($fileName, $dispretionPath);
$ioAdapter = new Varien_Io_File();
$ioAdapter->setAllowCreateFolders(true);
$distanationDirectory = dirname($this->_getConfig()->getTmpMediaPath($fileName));
try {
$ioAdapter->open(array('path' => $distanationDirectory));
/** @var $storageHelper Mage_Core_Helper_File_Storage_Database */
$storageHelper = Mage::helper('core/file_storage_database');
if ($move) {
$ioAdapter->mv($file, $this->_getConfig()->getTmpMediaPath($fileName));
//If this is used, filesystem should be configured properly
$storageHelper->saveFile($this->_getConfig()->getTmpMediaShortUrl($fileName));
} else {
$ioAdapter->cp($file, $this->_getConfig()->getTmpMediaPath($fileName));
$storageHelper->saveFile($this->_getConfig()->getTmpMediaShortUrl($fileName));
$ioAdapter->chmod($this->_getConfig()->getTmpMediaPath($fileName), 0777);
}
} catch (Exception $e) {
Mage::throwException(Mage::helper('catalog')->__('Failed to move file: %s', $e->getMessage()));
}
$fileName = str_replace(DS, '/', $fileName);
$attrCode = $this->getAttribute()->getAttributeCode();
$mediaGalleryData = $product->getData($attrCode);
$position = 0;
if (!is_array($mediaGalleryData)) {
$mediaGalleryData = array('images' => array());
}
foreach ($mediaGalleryData['images'] as &$image) {
if (isset($image['position']) && $image['position'] > $position) {
$position = $image['position'];
}
}
$position++;
$mediaGalleryData['images'][] = array('file' => $fileName, 'position' => $position, 'label' => '', 'disabled' => (int) $exclude);
$product->setData($attrCode, $mediaGalleryData);
if (!is_null($mediaAttribute)) {
$this->setMediaAttribute($product, $mediaAttribute, $fileName);
}
return $fileName;
}
示例5: saveRow
//.........这里部分代码省略.........
if (isset($filearrayforimport)) {
$filecounterinternall = 1;
foreach ($filearrayforimport as $fileinfo) {
$document_directory = Mage::getBaseDir('media') . DS . 'import' . DS;
$files = $fileinfo['file'];
#echo "FILE: " . $fileinfo['file'];
#echo "ID: " . $product->getId();
$resource = Mage::getSingleton('core/resource');
$prefix = Mage::getConfig()->getNode('global/resources/db/table_prefix');
$write = $resource->getConnection('core_write');
$read = $resource->getConnection('core_read');
$select_qry = $read->query("SHOW TABLE STATUS LIKE '" . $prefix . "downloadable_link' ");
$row = $select_qry->fetch();
$next_id = $row['Auto_increment'];
$okvalueformodelID = $next_id - $filecounterinternall;
#echo "next_id: " . $okvalueformodelID;
$linkModel = Mage::getModel('downloadable/link')->load($okvalueformodelID);
$link_file = $document_directory . $files;
$file = realpath($link_file);
if (!$file || !file_exists($file)) {
Mage::throwException(Mage::helper('catalog')->__('Link file ' . $file . ' not exists'));
}
$pathinfo = pathinfo($file);
$linkfile = Varien_File_Uploader::getCorrectFileName($pathinfo['basename']);
$dispretionPath = Varien_File_Uploader::getDispretionPath($linkfile);
$linkfile = $dispretionPath . DS . $linkfile;
$linkfile = $dispretionPath . DS . Varien_File_Uploader::getNewFileName(Mage_Downloadable_Model_Link::getBasePath() . DS . $linkfile);
$ioAdapter = new Varien_Io_File();
$ioAdapter->setAllowCreateFolders(true);
$distanationDirectory = dirname(Mage_Downloadable_Model_Link::getBasePath() . DS . $linkfile);
try {
$ioAdapter->open(array('path' => $distanationDirectory));
$ioAdapter->cp($file, Mage_Downloadable_Model_Link::getBasePath() . DS . $linkfile);
$ioAdapter->chmod(Mage_Downloadable_Model_Link::getBasePath() . DS . $linkfile, 0777);
} catch (Exception $e) {
Mage::throwException(Mage::helper('catalog')->__('Failed to move file: %s', $e->getMessage()));
Mage::log(sprintf('failed to move file: %s', $e->getMessage()), null, 'ce_product_import_export_errors.log');
}
$linkfile = str_replace(DS, '/', $linkfile);
#echo "SET: " . $linkfile;
$linkModel->setLinkFile($linkfile);
$linkModel->save();
$intesdf = $next_id - $filecounterinternall;
$write->query("UPDATE `" . $prefix . "downloadable_link_title` SET title = '" . $fileinfo['name'] . "' WHERE link_id = '" . $intesdf . "'");
$write->query("UPDATE `" . $prefix . "downloadable_link_price` SET price = '" . $fileinfo['price'] . "' WHERE link_id = '" . $intesdf . "'");
#$product->setLinksPurchasedSeparately(false);
#$product->setLinksPurchasedSeparately(0);
$filecounterinternall++;
}
}
/* END DOWNLOADBLE METHOD */
/* SAMPLE FILE DOWNLOADBLE PRODUCT SAMPLE FILE METHOD START */
#print_r($filenameforsamplearrayforimport);
if (isset($filenameforsamplearrayforimport)) {
$filecounterinternall = 1;
foreach ($filenameforsamplearrayforimport as $fileinfo) {
$document_directory = Mage::getBaseDir('media') . DS . 'import';
$samplefiles = $fileinfo['file'];
#print_r($filenameforsamplearrayforimport);
#echo "ID: " . $fileinfo['name'] ."<br/>";
$resource = Mage::getSingleton('core/resource');
$prefix = Mage::getConfig()->getNode('global/resources/db/table_prefix');
$write = $resource->getConnection('core_write');
$read = $resource->getConnection('core_read');
$select_qry = $read->query("SHOW TABLE STATUS LIKE '" . $prefix . "downloadable_link' ");
$row = $select_qry->fetch();
示例6: _processDownloadableProduct
protected function _processDownloadableProduct($product, &$importData)
{
// comment if --------------------------
//if ($new) {
$filearrayforimports = array();
$downloadableitems = array();
$downloadableitemsoptionscount = 0;
//THIS IS FOR DOWNLOADABLE OPTIONS
$commadelimiteddata = explode('|', $importData['downloadable_options']);
foreach ($commadelimiteddata as $data) {
$configBundleOptionsCodes = $this->userCSVDataAsArray($data);
$downloadableitems['link'][$downloadableitemsoptionscount]['is_delete'] = 0;
$downloadableitems['link'][$downloadableitemsoptionscount]['link_id'] = 0;
$downloadableitems['link'][$downloadableitemsoptionscount]['title'] = $configBundleOptionsCodes[0];
$downloadableitems['link'][$downloadableitemsoptionscount]['price'] = $configBundleOptionsCodes[1];
$downloadableitems['link'][$downloadableitemsoptionscount]['number_of_downloads'] = $configBundleOptionsCodes[2];
$downloadableitems['link'][$downloadableitemsoptionscount]['is_shareable'] = 2;
if (isset($configBundleOptionsCodes[5])) {
#$downloadableitems['link'][$downloadableitemsoptionscount]['sample'] = '';
$downloadableitems['link'][$downloadableitemsoptionscount]['sample'] = array('file' => '[]', 'type' => 'url', 'url' => '' . $configBundleOptionsCodes[5] . '');
} else {
$downloadableitems['link'][$downloadableitemsoptionscount]['sample'] = '';
}
$downloadableitems['link'][$downloadableitemsoptionscount]['file'] = '';
$downloadableitems['link'][$downloadableitemsoptionscount]['type'] = $configBundleOptionsCodes[3];
#$downloadableitems['link'][$downloadableitemsoptionscount]['link_url'] = $configBundleOptionsCodes[4];
if ($configBundleOptionsCodes[3] == "file") {
#$filearrayforimport = array('file' => 'media/import/mypdf.pdf' , 'name' => 'asdad.txt', 'size' => '316', 'status' => 'old');
#$document_directory = Mage :: getBaseDir( 'media' ) . DS . 'import' . DS;
#echo "DIRECTORY: " . $document_directory;
#$filearrayforimport = '[{"file": "/home/discou33/public_html/media/import/mypdf.pdf", "name": "mypdf.pdf", "status": "new"}]';
#$filearrayforimport = '[{"file": "mypdf.pdf", "name": "quickstart.pdf", "size": 324075, "status": "new"}]';
#$product->setLinksPurchasedSeparately(0);
#$product->setLinksPurchasedSeparately(false);
#$files = Zend_Json::decode($filearrayforimport);
#$files = "mypdf.pdf";
//--------------- upload file ------------------
$document_directory = Mage::getBaseDir('media') . DS . 'import' . DS . $this->__vendorName . DS;
$files = '' . $configBundleOptionsCodes[4] . '';
$link_file = $document_directory . $files;
$file = realpath($link_file);
if (!$file || !file_exists($file)) {
Mage::throwException(Mage::helper('catalog')->__($rowInfo . 'Link file ' . $file . ' not exists'));
}
$pathinfo = pathinfo($file);
$linkfile = Varien_File_Uploader::getCorrectFileName($pathinfo['basename']);
$dispretionPath = Varien_File_Uploader::getDispretionPath($linkfile);
$linkfile = $dispretionPath . DS . $linkfile;
$linkfile = $dispretionPath . DS . Varien_File_Uploader::getNewFileName(Mage_Downloadable_Model_Link::getBaseTmpPath() . DS . $linkfile);
$ioAdapter = new Varien_Io_File();
$ioAdapter->setAllowCreateFolders(true);
$distanationDirectory = dirname(Mage_Downloadable_Model_Link::getBaseTmpPath() . DS . $linkfile);
try {
$ioAdapter->open(array('path' => $distanationDirectory));
$ioAdapter->cp($file, Mage_Downloadable_Model_Link::getBaseTmpPath() . DS . $linkfile);
$ioAdapter->chmod(Mage_Downloadable_Model_Link::getBaseTmpPath() . DS . $linkfile, 0777);
} catch (exception $e) {
Mage::throwException(Mage::helper('catalog')->__('Failed to move file: %s', $e->getMessage()));
}
//{"file": "/2/_/2.jpg", "name": "2.jpg", "size": 23407, "status": "new"}
$linkfile = str_replace(DS, '/', $linkfile);
$filearrayforimports = array(array('file' => $linkfile, 'name' => $pathinfo['filename'] . '.' . $pathinfo['extension'], 'status' => 'new', 'size' => filesize($file)));
if (isset($configBundleOptionsCodes[5])) {
if ($configBundleOptionsCodes[5] == 0) {
$linkspurchasedstatus = 0;
$linkspurchasedstatustext = false;
} else {
$linkspurchasedstatus = 1;
$linkspurchasedstatustext = true;
}
$product->setLinksPurchasedSeparately($linkspurchasedstatus);
$product->setLinksPurchasedSeparately($linkspurchasedstatustext);
}
//$downloadableitems['link'][$downloadableitemsoptionscount]['link_file'] = $linkfile;
$downloadableitems['link'][$downloadableitemsoptionscount]['file'] = Mage::helper('core')->jsonEncode($filearrayforimports);
} else {
if ($configBundleOptionsCodes[3] == "url") {
$downloadableitems['link'][$downloadableitemsoptionscount]['link_url'] = $configBundleOptionsCodes[4];
}
}
$downloadableitems['link'][$downloadableitemsoptionscount]['sort_order'] = 0;
$product->setDownloadableData($downloadableitems);
$downloadableitemsoptionscount += 1;
}
#print_r($downloadableitems);
//}
}
示例7: addImage
/**
* Add image to media gallery and return new filename
*
* @param Mage_Catalog_Model_Product $product
* @param string $file file path of image in file system
* @param string|array $mediaAttribute code of attribute with type 'media_image',
* leave blank if image should be only in gallery
* @param boolean $move if true, it will move source file
* @param boolean $exclude mark image as disabled in product page view
* @return string
*/
public function addImage(Mage_Catalog_Model_Product $product, $file, $mediaAttribute = null, $move = false, $exclude = true)
{
$file = realpath($file);
if (!$file) {
AO::throwException(AO::helper('catalog')->__('Image not exists'));
}
$pathinfo = pathinfo($file);
if (!isset($pathinfo['extension']) || !in_array($pathinfo['extension'], array('jpg', 'jpeg', 'gif', 'png'))) {
AO::throwException(AO::helper('catalog')->__('Invalid image file type'));
}
$fileName = Varien_File_Uploader::getCorrectFileName($pathinfo['basename']);
$dispretionPath = Varien_File_Uploader::getDispretionPath($fileName);
$fileName = $dispretionPath . DS . $fileName;
$fileName = $dispretionPath . DS . Varien_File_Uploader::getNewFileName($this->_getConfig()->getTmpMediaPath($fileName));
$ioAdapter = new Varien_Io_File();
$ioAdapter->setAllowCreateFolders(true);
$distanationDirectory = dirname($this->_getConfig()->getTmpMediaPath($fileName));
try {
$ioAdapter->open(array('path' => $distanationDirectory));
if ($move) {
$ioAdapter->mv($file, $this->_getConfig()->getTmpMediaPath($fileName));
} else {
$ioAdapter->cp($file, $this->_getConfig()->getTmpMediaPath($fileName));
$ioAdapter->chmod($this->_getConfig()->getTmpMediaPath($fileName), 0777);
}
} catch (Exception $e) {
AO::throwException(AO::helper('catalog')->__('Failed to move file: %s', $e->getMessage()));
}
$fileName = str_replace(DS, '/', $fileName);
$attrCode = $this->getAttribute()->getAttributeCode();
$mediaGalleryData = $product->getData($attrCode);
$position = 0;
if (!is_array($mediaGalleryData)) {
$mediaGalleryData = array('images' => array());
}
foreach ($mediaGalleryData['images'] as &$image) {
if (isset($image['position']) && $image['position'] > $position) {
$position = $image['position'];
}
}
$position++;
$mediaGalleryData['images'][] = array('file' => $fileName, 'position' => $position, 'label' => '', 'disabled' => (int) $exclude);
$product->setData($attrCode, $mediaGalleryData);
if (!is_null($mediaAttribute)) {
$this->setMediaAttribute($product, $mediaAttribute, $fileName);
}
return $fileName;
}
示例8: resetAllThemes
/**
* Reset all theme color changes
* Copy media/xmlconnect/themes/default/* to media/xmlconnect/themes/*
*
* @return void
*/
public function resetAllThemes()
{
$themeDir = Mage::getBaseDir('media') . DS . 'xmlconnect' . DS . 'themes';
$defaultThemeDir = Mage::getBaseDir('media') . DS . 'xmlconnect' . DS . 'themes' . DS . 'default';
$io = new Varien_Io_File();
$io->open(array('path' => $defaultThemeDir));
$fileList = $io->ls(Varien_Io_File::GREP_FILES);
foreach ($fileList as $file) {
$f = $file['text'];
$src = $defaultThemeDir . DS . $f;
$dst = $themeDir . DS . $f;
if ($io->isWriteable($dst)) {
try {
if (!$io->cp($src, $dst)) {
Mage::throwException(Mage::helper('xmlconnect')->__('Can\\t copy file "%s" to "%s".', $src, $dst));
} else {
$io->chmod($dst, 0755);
}
} catch (Exception $e) {
Mage::logException($e);
}
}
}
}
示例9: uploadThumbnail
public function uploadThumbnail($thumbnail, $correctFile = null)
{
// If no thumbnail specified, use placeholder image
if (!$thumbnail) {
// Check if placeholder defined in config
$isConfigPlaceholder = Mage::getStoreConfig("catalog/placeholder/image_placeholder");
$configPlaceholder = '/placeholder/' . $isConfigPlaceholder;
if ($isConfigPlaceholder && file_exists(Mage::getBaseDir('media') . '/catalog/product' . $configPlaceholder)) {
$thumbnail = Mage::getBaseDir('media') . '/catalog/product' . $configPlaceholder;
} else {
// Replace file with skin or default skin placeholder
$skinBaseDir = Mage::getDesign()->getSkinBaseDir();
$skinPlaceholder = "/images/catalog/product/placeholder/image.jpg";
$thumbnail = $skinPlaceholder;
if (file_exists($skinBaseDir . $thumbnail)) {
$baseDir = $skinBaseDir;
} else {
$baseDir = Mage::getDesign()->getSkinBaseDir(array('_theme' => 'default'));
if (!file_exists($baseDir . $thumbnail)) {
$baseDir = Mage::getDesign()->getSkinBaseDir(array('_theme' => 'default', '_package' => 'base'));
}
if (!file_exists($baseDir . $thumbnail)) {
$baseDir = Mage::getDesign()->getSkinBaseDir(array('_theme' => 'default', '_package' => 'default'));
}
}
$thumbnail = str_replace('adminhtml', 'frontend', $baseDir) . $thumbnail;
}
}
if (!$correctFile) {
$correctFile = basename($thumbnail);
}
$tempFile = null;
if (Mage::helper('videogallery')->isUrl($thumbnail)) {
// Get Temporary location where we can save thumbnail to
$adapter = new Varien_Io_File();
$tempFile = $adapter->getCleanPath(Mage::getBaseDir('tmp')) . $correctFile;
// Download to the temp location
$thumbData = Mage::helper('videogallery')->file_get_contents_curl($thumbnail);
@file_put_contents($tempFile, $thumbData);
@chmod($tempFile, 0777);
unset($thumbData);
$thumbnail = $tempFile;
}
// Getting ready to download and save thumbnail
$fileName = Varien_File_Uploader::getCorrectFileName($correctFile);
$dispretionPath = Varien_File_Uploader::getDispretionPath($fileName);
//$fileName = $dispretionPath . DS . $fileName;
$fileName = $dispretionPath . DS . Varien_File_Uploader::getNewFileName($this->_getConfig()->getMediaPath($fileName));
$ioAdapter = new Varien_Io_File();
$ioAdapter->setAllowCreateFolders(true);
$destinationDirectory = dirname($this->_getConfig()->getMediaPath($fileName));
try {
$ioAdapter->open(array('path' => $destinationDirectory));
if (!$ioAdapter->cp($thumbnail, $this->_getConfig()->getMediaPath($fileName))) {
return false;
}
$ioAdapter->chmod($this->_getConfig()->getMediaPath($fileName), 0777);
if ($tempFile) {
$ioAdapter->rm($tempFile);
}
} catch (Exception $e) {
Mage::throwException(Mage::helper('videogallery')->__($e->getMessage()));
}
$fileName = str_replace(DS, '/', $fileName);
return $fileName;
}