本文整理汇总了PHP中Jaws_Utils::rename方法的典型用法代码示例。如果您正苦于以下问题:PHP Jaws_Utils::rename方法的具体用法?PHP Jaws_Utils::rename怎么用?PHP Jaws_Utils::rename使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Jaws_Utils
的用法示例。
在下文中一共展示了Jaws_Utils::rename方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: rename
/**
* Renames/Moves a file or directory
*
* @access public
* @param string $source Path to the source file or directory
* @param string $dest The destination path
* @param bool $overwrite Overwrite files if exists
* @return bool True if success, False otherwise
* @see http://www.php.net/rename
*/
static function rename($source, $dest, $overwrite = true)
{
$result = false;
if (file_exists($source)) {
if (file_exists($dest)) {
if (is_dir($source)) {
if (false !== ($hDir = @opendir($source))) {
while (false !== ($file = @readdir($hDir))) {
if ($file == '.' || $file == '..') {
continue;
}
$result = Jaws_Utils::rename($source . DIRECTORY_SEPARATOR . $file, $dest . DIRECTORY_SEPARATOR . $file, $overwrite);
if (!$result) {
break;
}
}
closedir($hDir);
Jaws_Utils::delete($source);
}
} else {
if (!$overwrite) {
$destinfo = pathinfo($dest);
$dest = $destinfo['dirname'] . DIRECTORY_SEPARATOR . $destinfo['filename'] . '_' . uniqid(floor(microtime() * 1000));
if (isset($destinfo['extension']) && !empty($destinfo['extension'])) {
$dest .= '.' . $destinfo['extension'];
}
}
$result = @rename($source, $dest);
if ($result) {
$result = $dest;
}
}
} else {
$result = @rename($source, $dest);
if ($result) {
$result = $dest;
}
}
}
return $result;
}
示例2: SendMessage
//.........这里部分代码省略.........
$data['insert_time'] = time();
$senderMessageId = $mTable->insert($data)->exec();
}
} else {
// update message
$mTable->update($data)->where('id', $messageData['id'])->exec();
$senderMessageId = $messageData['id'];
}
// Insert message for every recipient
if (!empty($recipient_users) && count($recipient_users) > 0) {
$table = $table->table('pm_messages');
$from = $is_notification ? 0 : $user;
$data['folder'] = $messageData['folder'];
foreach ($recipient_users as $recipient_user) {
$data['insert_time'] = time();
$data['from'] = $from;
$data['to'] = $recipient_user;
$data['read'] = false;
$messageId = $table->insert($data)->exec();
if (Jaws_Error::IsError($messageId)) {
//Rollback Transaction
$table->rollback();
return false;
}
$messageIds[] = $messageId;
// send notification on new private message
if (!$is_notification) {
$params = array();
$params['key'] = crc32('PrivateMessage' . $senderMessageId);
$params['title'] = _t('PRIVATEMESSAGE_NEW_MESSAGE_NOTIFICATION_TITLE');
$params['summary'] = _t('PRIVATEMESSAGE_NEW_MESSAGE_NOTIFICATION');
$params['description'] = _t('PRIVATEMESSAGE_NEW_MESSAGE_NOTIFICATION_DESC', $data['subject']);
$params['user'] = (int) $recipient_user;
$this->gadget->event->shout('Notify', $params);
}
}
}
}
// Insert attachments info
if (!empty($messageData['attachments']) && count($messageData['attachments']) > 0) {
$maData = array();
$pm_dir = JAWS_DATA . 'pm' . DIRECTORY_SEPARATOR . 'attachments' . DIRECTORY_SEPARATOR;
foreach ($messageData['attachments'] as $attachment) {
// check new attachments file -- we must copy tmp files to correct location
if (is_array($attachment)) {
$src_filepath = Jaws_Utils::upload_tmp_dir() . '/' . $attachment['filename'];
$dest_filepath = $pm_dir . $attachment['filename'];
if (!file_exists($src_filepath)) {
continue;
}
if (!file_exists($pm_dir)) {
if (!Jaws_Utils::mkdir($pm_dir)) {
return new Jaws_Error(_t('GLOBAL_ERROR_FAILED_CREATING_DIR', JAWS_DATA));
}
}
$cres = Jaws_Utils::rename($src_filepath, $dest_filepath);
Jaws_Utils::delete($src_filepath);
if ($cres) {
$aData = array('title' => $attachment['title'], 'filename' => $attachment['filename'], 'filesize' => $attachment['filesize'], 'filetype' => $attachment['filetype']);
$table = $table->table('pm_attachments');
$attachmentId = $table->insert($aData)->exec();
if (Jaws_Error::IsError($attachmentId)) {
//Rollback Transaction
$table->rollback();
return false;
}
// Add sender message Id to pm_message_attachment table
$maData[] = array('message' => $senderMessageId, 'attachment' => $attachmentId);
// Add recipient message Id to pm_message_attachment table
foreach ($messageIds as $messageId) {
$maData[] = array('message' => $messageId, 'attachment' => $attachmentId);
}
}
} else {
// Add sender message Id to pm_message_attachment table
$maData[] = array('message' => $senderMessageId, 'attachment' => $attachment);
// Add recipient message Id to pm_message_attachment table
foreach ($messageIds as $messageId) {
$maData[] = array('message' => $messageId, 'attachment' => $attachment);
}
}
}
if (!empty($maData) && count($maData) > 0) {
$table = $table->table('pm_message_attachment');
$res = $table->insertAll(array('message', 'attachment'), $maData)->exec();
if (Jaws_Error::IsError($res)) {
//Rollback Transaction
$table->rollback();
return false;
}
} else {
//Rollback Transaction
$table->rollback();
return false;
}
}
//Commit Transaction
$mTable->commit();
return $senderMessageId;
}
示例3: LogToFile
/**
* Logs the message to a file specified on the dest parameter
*
* @access public
* @param string $priority How to log
* @param string $file Filename
* @param string $line File line number
* @param string $msg Message to log
* @param string $opts Options(log file name, ...)
* @return void
*/
function LogToFile($priority, $file, $line, $msg, $opts)
{
if (isset($opts['file'])) {
$logfile = $opts['file'];
} else {
trigger_error("You need to set at least the filename for Jaws_Log::LogToFile", E_USER_ERROR);
}
// log file rotation
if (isset($opts['size']) && @filesize($logfile) >= $opts['size']) {
Jaws_Utils::rename($logfile, $logfile . '.' . time());
}
if (false !== ($fh = @fopen($logfile, 'a+'))) {
fwrite($fh, $this->getLogString($priority, $file, $line, $msg) . "\n");
fclose($fh);
}
}
示例4: UpdateFile
/**
* Updates file
*
* @access public
* @return array Response array
*/
function UpdateFile()
{
try {
// Validate data
$data = jaws()->request->fetch(array('id', 'title', 'description', 'parent', 'hidden', 'user_filename', 'host_filename', 'filetype', 'filesize'));
if (empty($data['title'])) {
throw new Exception(_t('DIRECTORY_ERROR_INCOMPLETE_DATA'));
}
$data['title'] = Jaws_XSS::defilter($data['title']);
$data['description'] = Jaws_XSS::defilter($data['description']);
$model = $this->gadget->model->loadAdmin('Files');
// Validate file
$id = (int) $data['id'];
$file = $model->GetFile($id);
if (Jaws_Error::IsError($file)) {
throw new Exception($file->getMessage());
}
// Upload file
$path = $GLOBALS['app']->getDataURL('directory');
if (!is_dir($path)) {
if (!Jaws_Utils::mkdir($path, 2)) {
throw new Exception('DIRECTORY_ERROR_FILE_UPLOAD');
}
}
$res = Jaws_Utils::UploadFiles($_FILES, $path, '', null);
if (Jaws_Error::IsError($res)) {
throw new Exception($res->getMessage());
} else {
if ($res !== false) {
$data['host_filename'] = $res['file'][0]['host_filename'];
$data['user_filename'] = $res['file'][0]['user_filename'];
$data['filetype'] = $res['file'][0]['host_filetype'];
$data['filesize'] = $res['file'][0]['host_filesize'];
} else {
if ($data['host_filename'] === ':nochange:') {
unset($data['host_filename']);
} else {
if (empty($data['host_filename'])) {
throw new Exception(_t('DIRECTORY_ERROR_FILE_UPLOAD'));
} else {
$filename = Jaws_Utils::upload_tmp_dir() . '/' . $data['host_filename'];
if (file_exists($filename)) {
$target = $path . '/' . $data['host_filename'];
$res = Jaws_Utils::rename($filename, $target, false);
if ($res === false) {
throw new Exception(_t('DIRECTORY_ERROR_FILE_UPLOAD'));
}
$data['host_filename'] = basename($res);
} else {
throw new Exception(_t('DIRECTORY_ERROR_FILE_UPLOAD'));
}
}
}
}
}
// Update file in database
unset($data['user']);
$data['updatetime'] = time();
$data['hidden'] = $data['hidden'] ? true : false;
$model = $this->gadget->model->loadAdmin('Files');
$res = $model->Update($id, $data);
if (Jaws_Error::IsError($res)) {
throw new Exception(_t('DIRECTORY_ERROR_FILE_UPDATE'));
}
// Update Tags
if (Jaws_Gadget::IsGadgetInstalled('Tags')) {
$tags = jaws()->request->fetch('tags');
$tModel = Jaws_Gadget::getInstance('Tags')->model->loadAdmin('Tags');
$tModel->UpdateReferenceTags('Directory', 'file', $id, !$data['hidden'], time(), $tags);
}
} catch (Exception $e) {
return $GLOBALS['app']->Session->GetResponse($e->getMessage(), RESPONSE_ERROR);
}
return $GLOBALS['app']->Session->GetResponse(_t('DIRECTORY_NOTICE_FILE_UPDATED'), RESPONSE_NOTICE);
}
示例5: UpdateFile
/**
* Updates file
*
* @access public
* @return array Response array
*/
function UpdateFile()
{
try {
// Validate data
$data = jaws()->request->fetch(array('id', 'title', 'description', 'parent', 'url', 'filename', 'filetype', 'filesize'));
if (empty($data['title'])) {
throw new Exception(_t('DIRECTORY_ERROR_INCOMPLETE_DATA'));
}
$data['title'] = Jaws_XSS::defilter($data['title']);
$data['description'] = Jaws_XSS::defilter($data['description']);
$model = $this->gadget->model->load('Files');
// Validate file
$id = (int) $data['id'];
$file = $model->GetFile($id);
if (Jaws_Error::IsError($file)) {
throw new Exception($file->getMessage());
}
// Validate user
$user = (int) $GLOBALS['app']->Session->GetAttribute('user');
if ($file['user'] != $user) {
throw new Exception(_t('DIRECTORY_ERROR_FILE_UPDATE'));
}
// Upload file
if ($file['user'] != $file['owner']) {
// is shortcut
unset($data['parent'], $data['url'], $data['filename']);
unset($data['filetype'], $data['filesize']);
} else {
$path = $GLOBALS['app']->getDataURL('directory/' . $user);
if (!is_dir($path)) {
if (!Jaws_Utils::mkdir($path, 2)) {
throw new Exception('DIRECTORY_ERROR_FILE_UPLOAD');
}
}
$res = Jaws_Utils::UploadFiles($_FILES, $path);
if (Jaws_Error::IsError($res)) {
throw new Exception($res->getMessage());
} else {
if ($res !== false) {
$data['filename'] = $res['file'][0]['host_filename'];
$data['filetype'] = $res['file'][0]['host_filetype'];
$data['filesize'] = $res['file'][0]['host_filesize'];
} else {
if ($data['filename'] === ':nochange:') {
unset($data['filename']);
} else {
if (empty($data['filename'])) {
throw new Exception(_t('DIRECTORY_ERROR_FILE_UPLOAD'));
} else {
$filename = Jaws_Utils::upload_tmp_dir() . '/' . $data['filename'];
if (file_exists($filename)) {
$target = $path . '/' . $data['filename'];
$res = Jaws_Utils::rename($filename, $target, false);
if ($res === false) {
throw new Exception(_t('DIRECTORY_ERROR_FILE_UPLOAD'));
}
$data['filename'] = basename($res);
} else {
throw new Exception(_t('DIRECTORY_ERROR_FILE_UPLOAD'));
}
}
}
}
}
}
// Update file in database
$data['updatetime'] = time();
$model = $this->gadget->model->load('Files');
$res = $model->Update($id, $data);
if (Jaws_Error::IsError($res)) {
throw new Exception(_t('DIRECTORY_ERROR_FILE_UPDATE'));
}
// Update shortcuts
if ($file['shared']) {
$shortcut = array();
$shortcut['url'] = $data['url'];
$shortcut['filename'] = $data['filename'];
$shortcut['filetype'] = $data['filetype'];
$shortcut['filesize'] = $data['filesize'];
$shortcut['updatetime'] = $data['updatetime'];
$model->UpdateShortcuts($id, $shortcut);
}
} catch (Exception $e) {
return $GLOBALS['app']->Session->GetResponse($e->getMessage(), RESPONSE_ERROR);
}
return $GLOBALS['app']->Session->GetResponse(_t('DIRECTORY_NOTICE_FILE_UPDATED'), RESPONSE_NOTICE);
}