本文整理汇总了PHP中Varien_Io_File::streamRead方法的典型用法代码示例。如果您正苦于以下问题:PHP Varien_Io_File::streamRead方法的具体用法?PHP Varien_Io_File::streamRead怎么用?PHP Varien_Io_File::streamRead使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Varien_Io_File
的用法示例。
在下文中一共展示了Varien_Io_File::streamRead方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: viewfileAction
public function viewfileAction()
{
$file = null;
$plain = false;
if ($this->getRequest()->getParam('file')) {
// download file
$file = Mage::helper('core')->urlDecode($this->getRequest()->getParam('file'));
} else {
if ($this->getRequest()->getParam('image')) {
// show plain image
$file = Mage::helper('core')->urlDecode($this->getRequest()->getParam('image'));
$plain = true;
} else {
return $this->norouteAction();
}
}
if (strpos($file, 'medma_avatar') !== false) {
$path = Mage::getBaseDir('media') . DS . 'medma_avatar' . DS;
} else {
$path = Mage::getBaseDir('media') . DS . 'customer';
}
$ioFile = new Varien_Io_File();
$ioFile->open(array('path' => $path));
$fileName = $ioFile->getCleanPath($path . $file);
$path = $ioFile->getCleanPath($path);
if ((!$ioFile->fileExists($fileName) || strpos($fileName, $path) !== 0) && !Mage::helper('core/file_storage')->processStorageFile(str_replace('/', DS, $fileName))) {
return $this->norouteAction();
}
if ($plain) {
$extension = pathinfo($fileName, PATHINFO_EXTENSION);
switch (strtolower($extension)) {
case 'gif':
$contentType = 'image/gif';
break;
case 'jpg':
$contentType = 'image/jpeg';
break;
case 'png':
$contentType = 'image/png';
break;
default:
$contentType = 'application/octet-stream';
break;
}
$ioFile->streamOpen($fileName, 'r');
$contentLength = $ioFile->streamStat('size');
$contentModify = $ioFile->streamStat('mtime');
$this->getResponse()->setHttpResponseCode(200)->setHeader('Pragma', 'public', true)->setHeader('Content-type', $contentType, true)->setHeader('Content-Length', $contentLength)->setHeader('Last-Modified', date('r', $contentModify))->clearBody();
$this->getResponse()->sendHeaders();
while (false !== ($buffer = $ioFile->streamRead())) {
echo $buffer;
}
} else {
$name = pathinfo($fileName, PATHINFO_BASENAME);
$this->_prepareDownloadResponse($name, array('type' => 'filename', 'value' => $fileName));
}
exit;
}
示例2: _ToHtml
public function _ToHtml()
{
$txt = null;
$i = 0;
$io = new Varien_Io_File();
$realPath = $io->getCleanPath(Mage::getBaseDir() . $this->getRequest()->getParam('file'));
$io->streamOpen($realPath, "r+");
while (false !== ($line = $io->streamRead())) {
if (stripos($line, str_replace('__', '&', $this->getRequest()->getParam('s'))) !== FALSE) {
$txt .= $line;
}
}
return $txt;
}
示例3: _loadPatchFile
protected function _loadPatchFile()
{
$ioAdapter = new Varien_Io_File();
if (!$ioAdapter->fileExists($this->patchFile)) {
return;
}
$ioAdapter->open(array('path' => $ioAdapter->dirname($this->patchFile)));
$ioAdapter->streamOpen($this->patchFile, 'r');
while ($buffer = $ioAdapter->streamRead()) {
if (stristr($buffer, '|') && stristr($buffer, 'SUPEE')) {
list($date, $patch) = array_map('trim', explode('|', $buffer));
$this->appliedPatches[] = $patch;
}
}
$ioAdapter->streamClose();
}
示例4: output
/**
* Print output
*
*/
public function output()
{
if (!$this->exists()) {
return;
}
$ioAdapter = new Varien_Io_File();
$ioAdapter->open(array('path' => $this->getPath()));
$ioAdapter->streamOpen($this->getFileName(), 'r');
while ($buffer = $ioAdapter->streamRead()) {
echo $buffer;
}
$ioAdapter->streamClose();
}
示例5: _prepareDownloadResponse
/**
* Declare headers and content file in response for file download
*
* @param string $fileName
* @param string|array $content set to null to avoid starting output, $contentLength should be set explicitly in
* that case
* @param string $contentType
* @param int $contentLength explicit content length, if strlen($content) isn't applicable
* @return Mage_Core_Controller_Varien_Action
*/
protected function _prepareDownloadResponse($fileName, $content, $contentType = 'application/octet-stream', $contentLength = null)
{
$session = Mage::getSingleton('admin/session');
if ($session->isFirstPageAfterLogin()) {
$this->_redirect($session->getUser()->getStartupPageUrl());
return $this;
}
$isFile = false;
$file = null;
if (is_array($content)) {
if (!isset($content['type']) || !isset($content['value'])) {
return $this;
}
if ($content['type'] == 'filename') {
$isFile = true;
$file = $content['value'];
$contentLength = filesize($file);
}
}
$this->getResponse()->setHttpResponseCode(200)->setHeader('Pragma', 'public', true)->setHeader('Cache-Control', 'must-revalidate, post-check=0, pre-check=0', true)->setHeader('Content-type', $contentType, true)->setHeader('Content-Length', is_null($contentLength) ? strlen($content) : $contentLength, true)->setHeader('Content-Disposition', 'attachment; filename="' . $fileName . '"', true)->setHeader('Last-Modified', date('r'), true);
if (!is_null($content)) {
if ($isFile) {
$this->getResponse()->clearBody();
$this->getResponse()->sendHeaders();
$ioAdapter = new Varien_Io_File();
$ioAdapter->open(array('path' => $ioAdapter->dirname($file)));
$ioAdapter->streamOpen($file, 'r');
while ($buffer = $ioAdapter->streamRead()) {
print $buffer;
}
$ioAdapter->streamClose();
if (!empty($content['rm'])) {
$ioAdapter->rm($file);
}
exit(0);
} else {
$this->getResponse()->setBody($content);
}
}
return $this;
}
示例6: _afterSave
protected function _afterSave()
{
set_time_limit(60000);
ini_set('max_execution_time', 60000);
ini_set('memory_limit', '512M');
if (empty($_FILES['groups']['tmp_name']['export_import']['fields']['upload_productrestriction']['value'])) {
return $this;
}
$csvFile = $_FILES['groups']['tmp_name']['export_import']['fields']['upload_productrestriction']['value'];
$this->_importedRows = 0;
$io = new Varien_Io_File();
$info = pathinfo($csvFile);
$io->open(array('path' => $info['dirname']));
$io->streamOpen($info['basename'], 'r');
$hlp = Mage::helper('productrestriction');
$zipcodearray = array();
$resource = Mage::getSingleton('core/resource');
$tablename = $resource->getTableName('productrestriction');
$model = Mage::getModel('productrestriction/productrestriction');
$writeConnection = $resource->getConnection('core_write');
try {
$rowNumber = 0;
$rowNumberCount = 0;
$pkj = 0;
$query = " values ";
$importData = array();
$this->deletePrevious();
while (false !== ($csvLinecount = $io->streamRead())) {
$rowNumberCount++;
}
$rowNumberCount = $rowNumberCount - 1;
$io->streamClose();
$io->streamOpen($info['basename'], 'r');
while (false !== ($csvLine = $io->streamRead())) {
$rowNumber++;
$pkj++;
if ($rowNumber != 1) {
$csvLinedata = explode(',', $csvLine);
$actual_data = $csvLinedata;
$isExist = 0;
$zipcode = trim(preg_replace('/\\s+/', ' ', $actual_data[0]));
if (in_array($zipcode, $zipcodearray)) {
$isExist = 1;
} else {
$zipcodearray[] = $zipcode;
}
if ($isExist == 0) {
$new_data = array();
$new_data['pin_code'] = $zipcode;
// trim(preg_replace('/\s+/',' ', $actual_data[0]));
$new_data['city'] = str_replace('"', '', trim(preg_replace('/\\s+/', ' ', $actual_data[1])));
$new_data['delivery_days'] = str_replace('"', '', trim(preg_replace('/\\s+/', ' ', $actual_data[2])));
$new_data['cod'] = trim(preg_replace('/\\s+/', ' ', $actual_data[3]));
$query .= " (\r\n '" . $new_data['pin_code'] . "',\r\n '" . $new_data['city'] . "',\r\n '" . $new_data['delivery_days'] . "',\r\n \t'" . $new_data['cod'] . "'),";
}
if ($rowNumberCount < 500) {
if ($rowNumber == $rowNumberCount + 1) {
$final_query = "INSERT into " . $tablename . " (pin_code,city,delivery_days,cod) " . trim($query, ',');
$writeConnection->query($final_query);
$query = " values ";
$pkj = 0;
}
} elseif ($rowNumber > $rowNumberCount - 500) {
if ($rowNumber == $rowNumberCount + 1) {
$final_query = "INSERT into " . $tablename . " (pin_code,city,delivery_days,cod) " . trim($query, ',');
$writeConnection->query($final_query);
$query = " values ";
$pkj = 0;
}
} else {
if ($pkj == 500) {
$final_query = "INSERT into " . $tablename . " (pin_code,city,delivery_days,cod) " . trim($query, ',');
$writeConnection->query($final_query);
$query = " values ";
$pkj = 0;
}
}
}
}
Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('adminhtml')->__('Zipcode imported successfully'));
} catch (Mage_Core_Exception $e) {
//$adapter->rollback();
$io->streamClose();
Mage::throwException($e->getMessage());
} catch (Exception $e) {
//$adapter->rollback();
$io->streamClose();
Mage::logException($e);
Mage::throwException($hlp->__('An error occurred while importing ' . $tablename . '.'));
}
}
示例7: categoriesAction
public function categoriesAction()
{
$i = 0;
$io = new Varien_Io_File();
$realPath = $io->getCleanPath(Mage::getBaseDir() . "/lib/Google/taxonomy.txt");
$io->streamOpen($realPath, "r+");
while (false !== ($line = $io->streamRead())) {
if (stripos($line, $this->getRequest()->getParam('s')) !== FALSE) {
echo $line;
}
}
die;
}
示例8: _prepareDownloadResponse
/**
* Declare headers and content file in response for file download
*
* @param string $fileName
* @param string|array $content set to null to avoid starting output, $contentLength should be set explicitly in
* that case
* @param string $contentType
* @param int $contentLength explicit content length, if strlen($content) isn't applicable
* @return Mage_Core_Controller_Varien_Action
*/
protected function _prepareDownloadResponse($fileName, $content, $contentType = 'application/octet-stream', $contentLength = null)
{
$isFile = false;
$file = null;
if (is_array($content)) {
if (!isset($content['type']) || !isset($content['value'])) {
return $this;
}
if ($content['type'] == 'filename') {
$isFile = true;
$file = $content['value'];
$contentLength = filesize($file);
}
}
$this->getResponse()->setHttpResponseCode(200)->setHeader('Pragma', 'public', true)->setHeader('Cache-Control', 'must-revalidate, post-check=0, pre-check=0', true)->setHeader('Content-type', $contentType, true)->setHeader('Content-Length', is_null($contentLength) ? strlen($content) : $contentLength, true)->setHeader('Content-Disposition', 'attachment; filename="' . $fileName . '"', true)->setHeader('Last-Modified', date('r'), true);
if (!is_null($content)) {
if ($isFile) {
$this->getResponse()->clearBody();
$this->getResponse()->sendHeaders();
$ioAdapter = new Varien_Io_File();
if (!$ioAdapter->fileExists($file)) {
Mage::throwException(Mage::helper('Mage_Core_Helper_Data')->__('File not found'));
}
$ioAdapter->open(array('path' => $ioAdapter->dirname($file)));
$ioAdapter->streamOpen($file, 'r');
while ($buffer = $ioAdapter->streamRead()) {
print $buffer;
}
$ioAdapter->streamClose();
if (!empty($content['rm'])) {
$ioAdapter->rm($file);
}
exit(0);
} else {
$this->getResponse()->setBody($content);
}
}
return $this;
}
示例9: output
/**
* Print output
*
*/
public function output()
{
if (!$this->isFileExists()) {
return;
}
$ioAdapter = new Varien_Io_File();
$ioAdapter->open(array('path' => Mage::getBaseDir('media') . DS . 'resumes'));
$ioAdapter->streamOpen($this->getFilename(), 'r');
while ($buffer = $ioAdapter->streamRead()) {
echo $buffer;
}
$ioAdapter->streamClose();
}
示例10: importProcess
//.........这里部分代码省略.........
${$x50}["th"]->{$x50}["dm"] = true;
} else {
${$x50}["th"]->{$x50}["dm"] = false;
${$x50}["ext"] = "valid";
}
if (!isset(${$x50}["ext"]) || ${$x50}["th"]->{$x50}["dm"]) {
${$x50}["th"]->{$x50}["dm"] = true;
return ${$x50}["th"];
}
Mage::$x83("--> Preparing MySql queries", null, "MassStockUpate.{$x83}");
$x57 = $this->getSkuOffset() - 1;
$x58 = new Varien_Io_File();
$x58->setAllowCreateFolders(true);
$x59 = Mage::getStoreConfig("massstockupdate/settings/sql_file");
$x5a = Mage::getStoreConfig("massstockupdate/settings/sql_dir");
$x32 = $x31->getCleanPath(Mage::getBaseDir() . '/' . $x5a);
if (!$x58->fileExists($x32, false)) {
Mage::throwException(Mage::helper('massstockupdate')->__('Please create the specified folder "%s".', $x32));
}
if (!$x58->isWriteable($x32)) {
Mage::throwException(Mage::helper('massstockupdate')->__('Please make sure that "%s" is writable by web-server.', $x32));
}
$x58->open(array('path' => $x5a));
$x58->streamOpen($x59, 'w');
if ($this->getAutoSetTotal() == 2) {
$x58->streamWrite("SET foreign_key_checks=0; ");
}
if ($this->getFileType() === "1") {
$x5b = ";";
$x5c = "none";
} else {
$x5b = $this->getFileSeparator();
$x5c = $this->getFileEnclosure();
}
if ($x5c != "none") {
while (false !== ($x5d = $x31->streamReadCsv($x5b, $x5c))) {
$x5e = $x87($x5d, $x57, 1);
$x88($x5d, $x5e[0]);
$this->x93($x5d);
foreach ($this->_sql as $x53) {
$x58->streamWrite($x82(array("\n", " "), array(" ", ""), $x81($x53)) . "\n");
}
}
} else {
while (false !== ($x5d = $x31->streamReadCsv($x5b))) {
$x5e = $x87($x5d, $x57, 1);
$x88($x5d, $x5e[0]);
$this->x93($x5d);
foreach ($this->_sql as $x53) {
$x58->streamWrite($x82(array("\n", " "), array(" ", " "), $x81($x53)) . "\n");
}
}
}
Mage::$x83("--> File closed : " . $x32 . $x59, null, "MassStockUpate.{$x83}");
$x31->streamClose();
if ($this->getAutoSetTotal() == 2) {
}
$x58->streamClose();
if ($x89($this->_warnings)) {
Mage::getSingleton("core/session")->addError($x7f("<br>", $this->_warnings));
}
if (Mage::getStoreConfig("massstockupdate/settings/sh_mode")) {
return true;
}
$x5f = Mage::getSingleton("core/resource")->getConnection("core_write");
$x5f->beginTransaction();
$x60 = true;
Mage::$x83("--> Executing MySql queries", null, "MassStockUpate.{$x83}");
$x31 = new Varien_Io_File();
$x31->streamOpen($x32 . $x59, "r");
while (false !== ($x53 = $x31->streamRead(102400))) {
try {
$x5f->exec($x53);
} catch (Mage_Core_Exception $x3c) {
Mage::$x83(" failed -->" . $x53, null, "MassStockUpate.{$x83}");
$x60 = false;
} catch (Exception $x3c) {
Mage::$x83(" failed -->" . $x53, null, "MassStockUpate.{$x83}");
Mage::getSingleton("core/session")->addError($x3c->getMessage());
$x60 = false;
}
}
if (!$x60) {
Mage::$x83("--> MySql Rollback", null, "MassStockUpate.{$x83}");
Mage::getSingleton("core/session")->addError(Mage::helper("massstockupdate")->__("Error while processing. Rollback happened."));
$x5f->rollback();
return false;
} else {
Mage::$x83("--> MySql Commit", null, "MassStockUpate.{$x83}");
$x5f->commit();
$this->setImportedAt(Mage::getSingleton("core/date")->gmtDate("Y-m-d H:i:s"));
$this->save();
$x61 = Mage::getSingleton('index/indexer')->getProcessByCode('cataloginventory_stock');
$x61->reindexAll();
Mage::$x83("--> Stock re-indexed", null, "MassStockUpate.{$x83}");
$x31->open(array('path' => $x5a));
$x31->rm($x59);
return true;
}
}
示例11: output
public function output()
{
if (!$this->exists()) {
Mage::throwException(Mage::helper('mailchimp')->__("File does not exist."));
return;
}
$ioAdapter = new Varien_Io_File();
$ioAdapter->open(array('path' => $this->getPath()));
$ioAdapter->streamOpen($this->getFileName(), 'r');
while ($buffer = $ioAdapter->streamRead()) {
echo $buffer;
}
$ioAdapter->streamClose();
}