本文整理汇总了PHP中FileUpload::getFileSize方法的典型用法代码示例。如果您正苦于以下问题:PHP FileUpload::getFileSize方法的具体用法?PHP FileUpload::getFileSize怎么用?PHP FileUpload::getFileSize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FileUpload
的用法示例。
在下文中一共展示了FileUpload::getFileSize方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: actionUpload
public function actionUpload()
{
include __DIR__ . "./../uploader/Uploader.php";
$upload_dir = \Yii::$app->getModule("file")->getStorageDir();
$uploader = new \FileUpload('uploadfile');
$fileModel = new File();
$realName = $_GET["uploadfile"];
// Handle the upload
$isUplaoded = $uploader->handleUpload($upload_dir);
$result = false;
$errorMsg = '';
if ($isUplaoded) {
$fileModel = new File();
$fileModel->setAttribute("real_name", $realName);
$fileModel->setAttribute("name_on_server", $uploader->getSavedFileName());
$fileModel->setAttribute("size", $uploader->getFileSize());
if (!$fileModel->save()) {
$uploader->rollBack();
$errorMsg = "Entity save error";
} else {
if (!empty($_GET["relateTo"])) {
if (!$fileModel->linkWith($_GET["relateTo"])) {
$uploader->rollBack();
$fileModel->delete();
$errorMsg = "Entity link error";
} else {
$result = true;
}
} else {
$result = true;
}
}
} else {
$errorMsg = $uploader->getErrorMsg();
}
if ($result) {
echo json_encode(array('success' => true));
} else {
exit(json_encode(['success' => false, 'msg' => $errorMsg]));
}
}
示例2: date
$upload_name = 'file_' . date("Y-m-d_His.");
if (isset($_GET['file_tree'])) {
include dirname(__FILE__) . "/extras/php_file_tree.php";
die(php_file_tree($upload_dir, "javascript:shoWImg('[link]',[id])", $allowed_extensions));
}
if (isset($_GET['uploadfile'])) {
require dirname(__FILE__) . '/extras/Uploader.php';
$Upload = new FileUpload('uploadfile');
$ext = $Upload->getExtension();
// Get the extension of the uploaded file
$Upload->newFileName = $upload_name . $ext;
$result = $Upload->handleUpload($upload_dir, $allowed_extensions);
if (!$result) {
die(json_encode(array('success' => false, 'msg' => $Upload->getErrorMsg())));
} else {
die(json_encode(array('success' => true, 'FileName' => $Upload->getFileName(), 'Size' => $Upload->getFileSize(), 'SavedFile' => $Upload->getSavedFile(), 'Extension' => $Upload->getExtension())));
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>تحميل الملفات</title>
<link href="./assets/css/bootstrap.min.css" rel="stylesheet">
<link href="./assets/css/bootstrap-rtl.min.css" rel="stylesheet">
<link href="./assets/css/styles.css" rel="stylesheet">
<script src="./assets/js/jquery.min.js"></script>
示例3: testMoveFile
public function testMoveFile()
{
$tmpPath = realpath(__DIR__ . '/Sample') . '/upload.tmp';
$targetPath = realpath(__DIR__ . '/Sample') . '/upload_moved.txt';
$targetPath2 = realpath(__DIR__ . '/Sample') . '/upload_moved_xtracopy.txt';
if (file_exists($tmpPath)) {
if (!unlink($tmpPath)) {
$this->markTestSkipped('Temp upload file remains from old test and could not be removed');
return;
}
}
file_put_contents($tmpPath, 'TESTING_123');
if (file_exists($targetPath)) {
if (!unlink($targetPath)) {
$this->markTestSkipped('Moved upload file remains from old test and could not be removed');
return;
}
}
if (file_exists($targetPath2)) {
if (!unlink($targetPath2)) {
$this->markTestSkipped('Moved upload file (2) remains from old test and could not be removed');
return;
}
}
$expectedSize = filesize($tmpPath);
$file = new FileUpload();
$file->setTemporaryPath($tmpPath);
// Initial copy
$this->assertTrue($file->saveTo($targetPath));
// Ensure file is copied OK and temp path is gone
$this->assertFileExists($targetPath);
$this->assertFileNotExists($tmpPath);
$this->assertTrue(filesize($targetPath) == $expectedSize);
// Ensure that the file size and current path reported are accurate
$this->assertEquals($expectedSize, $file->getFileSize());
$this->assertEquals($targetPath, $file->getCurrentPath());
// Copy the file again to a second location
$this->assertTrue($file->saveTo($targetPath2));
$this->assertTrue(filesize($targetPath2) == $expectedSize);
$this->assertFileExists($targetPath);
$this->assertFileExists($targetPath2);
$this->assertFileNotExists($tmpPath);
$this->assertEquals($expectedSize, $file->getFileSize());
$this->assertEquals($targetPath2, $file->getCurrentPath());
// cleanup
@unlink($tmpPath);
@unlink($targetPath);
@unlink($targetPath2);
}