本文整理汇总了PHP中ZendT_Lib::getTmpDir方法的典型用法代码示例。如果您正苦于以下问题:PHP ZendT_Lib::getTmpDir方法的具体用法?PHP ZendT_Lib::getTmpDir怎么用?PHP ZendT_Lib::getTmpDir使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ZendT_Lib
的用法示例。
在下文中一共展示了ZendT_Lib::getTmpDir方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _clearFiles
private function _clearFiles()
{
$folder = ZendT_Lib::getTmpDir() . '/files/';
$dh = opendir($folder);
while ($handle = readdir($dh)) {
if (is_dir($folder . $handle) && $handle != '.' && $handle != '..') {
$files = glob($folder . $handle . "/*.*");
if (count($files) == 0) {
$path = $folder . $handle;
@rmdir($path);
} else {
foreach ($files as $file) {
$lastAccess = filemtime($file);
// 30 minutos
if (time() - $lastAccess > 30 * 60 * 1) {
@unlink($file);
}
}
}
}
}
closedir($dh);
}
示例2: pluploadAction
public function pluploadAction()
{
$this->_helper->layout->disableLayout();
$this->_helper->viewRenderer->setNoRender(true);
$json = new ZendT_Json_Result();
try {
$targetDir = ZendT_Lib::getTmpDir() . '/files/' . DIRECTORY_SEPARATOR . "plupload";
// Create target dir
if (!file_exists($targetDir)) {
@($result = mkdir($targetDir));
if (!$result) {
throw new ZendT_Exception_Error('Não foi possível criar o diretório "$targetDir".', 1001);
}
}
if (!file_exists($targetDir)) {
@($result = mkdir($targetDir));
if (!$result) {
throw new ZendT_Exception_Error('Não foi possível criar o diretório "$targetDir".', 1001);
}
}
//$targetDir = 'uploads';
$cleanupTargetDir = true;
// Remove old files
$maxFileAge = 1 * 3600;
// Temp file age in seconds
// 5 minutes execution time
@set_time_limit(5 * 60);
// Uncomment this one to fake upload time
// usleep(5000);
// Get parameters
$chunk = isset($_REQUEST["chunk"]) ? intval($_REQUEST["chunk"]) : 0;
$chunks = isset($_REQUEST["chunks"]) ? intval($_REQUEST["chunks"]) : 0;
$fileName = isset($_REQUEST["name"]) ? $_REQUEST["name"] : '';
// Clean the fileName for security reasons
$fileName = removeAccent(trim($fileName));
$fileName = preg_replace('/[^\\w\\._]+/', '_', $fileName);
$fileName = str_replace(' ', '_', $fileName);
// Make sure the fileName is unique but only if chunking is disabled
if ($chunks < 2 && file_exists($targetDir . DIRECTORY_SEPARATOR . $fileName)) {
$ext = strrpos($fileName, '.');
$fileName_a = substr($fileName, 0, $ext);
$fileName_b = substr($fileName, $ext);
$count = 1;
while (file_exists($targetDir . DIRECTORY_SEPARATOR . $fileName_a . '_' . $count . $fileName_b)) {
$count++;
}
$fileName = $fileName_a . '_' . $count . $fileName_b;
}
$filePath = $targetDir . DIRECTORY_SEPARATOR . $fileName;
// Remove old temp files
if ($cleanupTargetDir && is_dir($targetDir) && ($dir = opendir($targetDir))) {
while (($file = readdir($dir)) !== false) {
$tmpfilePath = $targetDir . DIRECTORY_SEPARATOR . $file;
// Remove temp file if it is older than the max age and is not the current file
if (preg_match('/\\.part$/', $file) && filemtime($tmpfilePath) < time() - $maxFileAge && $tmpfilePath != "{$filePath}.part") {
@unlink($tmpfilePath);
}
}
closedir($dir);
} else {
throw new ZendT_Exception_Error('Failed to open temp directory.', 100);
}
// Look for the content type header
if (isset($_SERVER["HTTP_CONTENT_TYPE"])) {
$contentType = $_SERVER["HTTP_CONTENT_TYPE"];
}
if (isset($_SERVER["CONTENT_TYPE"])) {
$contentType = $_SERVER["CONTENT_TYPE"];
}
// Handle non multipart uploads older WebKit versions didn't support multipart in HTML5
if (strpos($contentType, "multipart") !== false) {
if (isset($_FILES['file']['tmp_name']) && is_uploaded_file($_FILES['file']['tmp_name'])) {
// Open temp file
$out = fopen("{$filePath}.part", $chunk == 0 ? "wb" : "ab");
if ($out) {
// Read binary input stream and append it to temp file
$in = fopen($_FILES['file']['tmp_name'], "rb");
if ($in) {
while ($buff = fread($in, 4096)) {
fwrite($out, $buff);
}
} else {
throw new ZendT_Exception_Error('Failed to open input stream.', 101);
}
fclose($in);
fclose($out);
@unlink($_FILES['file']['tmp_name']);
} else {
throw new ZendT_Exception_Error('Failed to open output stream.', 102);
}
} else {
throw new ZendT_Exception_Error('Failed to move uploaded file.', 103);
}
} else {
// Open temp file
$out = fopen("{$filePath}.part", $chunk == 0 ? "wb" : "ab");
if ($out) {
// Read binary input stream and append it to temp file
$in = fopen("php://input", "rb");
if ($in) {
//.........这里部分代码省略.........
示例3: create
/**
* Cria o arquivo no servidor e retorna o caminho completo do mesmo
*
* @param string $name
* @param string $content
* @return \ZendT_File
* @throws ZendT_Exception_Error
*/
public function create($name = '', $content = '', $type = '', $id = '')
{
$this->_name = str_replace(':', '', $name);
if ($this->_name == '') {
$this->_name = md5(date('dmyhis') . rand(200000, 9999999999)) . '.tmp';
}
$this->_type = $type;
$this->setId($id);
// $filename = $this->getPathBase() . '/' . $this->getFolderBase() . '/' . $this->_name;
$this->getFolderBase();
$filename = ZendT_Lib::getTmpDir() . '/files' . '/' . $this->getFolderBase() . '/' . $this->_name;
if (file_exists($filename)) {
@unlink($filename);
}
@($result = fopen($filename, 'a+'));
if (!$result) {
$error = error_get_last();
throw new ZendT_Exception_Error('Erro ao criar o arquivo.' . substr($error['message'], 0, 1000));
}
if ($content) {
@($write = fwrite($result, $content));
if (!$write) {
$error = error_get_last();
throw new ZendT_Exception_Error('Erro ao escrever no arquivo.' . substr($error['message'], 0, 1000));
}
}
return $this;
}