本文整理汇总了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);
}