本文整理匯總了PHP中FSFile::generatepath方法的典型用法代碼示例。如果您正苦於以下問題:PHP FSFile::generatepath方法的具體用法?PHP FSFile::generatepath怎麽用?PHP FSFile::generatepath使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類FSFile
的用法示例。
在下文中一共展示了FSFile::generatepath方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: addFile
/**
* Prepares the saving process by generating the hash and the place where the file is stored.
*
* Called when this component receives an HTTP POST request to
* /$a/$b/$c/$file.
* The request body should contain a JSON object representing the file's
* attributes.
*/
public function addFile($callName, $input, $params = array())
{
$fileObject = $input;
$fileContent = $fileObject->getBody(true);
$fileObject->setBody(null);
$fileObject->setHash(sha1($fileContent));
$filePath = FSFile::generateFilePath(FSFile::getBaseDir(), $fileObject->getHash());
$fileObject->setAddress(FSFile::getBaseDir() . '/' . $fileObject->getHash());
if (!file_exists($this->config['DIR']['files'] . '/' . $filePath)) {
FSFile::generatepath($this->config['DIR']['files'] . '/' . dirname($filePath));
// writes the file to filesystem
$file = fopen($this->config['DIR']['files'] . '/' . $filePath, 'w');
if ($file) {
fwrite($file, $fileContent);
fclose($file);
$fileObject->setStatus(201);
} else {
$fileObject->addMessage("Datei konnte nicht im Dateisystem angelegt werden.");
$fileObject->setStatus(409);
Logger::Log('POST postFile failed', LogLevel::ERROR);
return Model::isCreated($fileObject);
}
}
// resets the file content
$fileObject->setBody(null);
// generate new file address, file size and file hash
$fileObject->setAddress($filePath);
$fileObject->setFileSize(filesize($this->config['DIR']['files'] . '/' . $filePath));
$fileObject->setHash(sha1_file($this->config['DIR']['files'] . '/' . $filePath));
$fileObject->setMimeType(MimeReader::get_mime($this->config['DIR']['files'] . '/' . $filePath));
return Model::isCreated($fileObject);
}