Cogitium / cogiupload
一个简单的PHP类,用于从表单上传、重命名和调整文件大小
1.0.0
2016-12-15 16:21 UTC
This package is not auto-updated.
Last update: 2024-09-23 14:18:29 UTC
README
类功能
- PHP上传文件的简单代码
- 上传、重命名和最终调整文件大小(稍后,尚未实现)
- 错误信息仅支持英文
- 如果出现错误,生成异常
- 兼容PHP 5.0及其以上版本
你可能需要它的原因
因为它真的很有趣来开发这个 ;)
许可证
即将推出。
安装与加载
目前,你只需将类文件复制到你想要的文件夹中。
包含内容
在下载中,你可以找到以下目录和文件。你会看到如下内容
cogiupload/
├── bat/
│ ├── checkstyle.bat
│ ├── phpdoc.bat
├── class/
│ └── CogiUpload.class.js
├── doc/
│ ├── ...
│ └── index.html
├── psr/
│ ├── ...
│ └── index.html
└── test/
├── testCogiUpload.php
├── image1.jpg
├── image2.gif
├── image3.png
├── image4.jpeg
├── fichier1.pdf
├── fichier2.doc
└── uploads
├── ...
└── ...
一个简单的示例
<?php
require_once("../class/CogiUpload.class.php");
if (isset($_FILES["myfile"])) {
var_dump($_FILES);
try {
/**
* Initialize the email and the sender detail
*/
$upload = new CogiUpload($_FILES["myfile"],
array("jpg", "gif"),
1000000);
/**
* Use the setters
*/
$upload->setPathToUpload('uploads');
//$upload->setNameForFile('mynewfile');
/**
* Process the file
*/
$url = $upload->processUpload();
?>
<h2>Upload done</h2>
<div>
<?php
echo "<p>Very good, the upload is done !</p>";
echo "<p>URL : " . $url. "</p>";
$upload->debug();
?>
</div>
<?php
} catch(Exception $e) {
echo '<p>Exception : ' . $e->getMessage() . '</p>';
$upload->debug();
}
}
?>
<h2>Please select a file to upload</h2>
<form method="post" action="#" enctype="multipart/form-data">
<label>File to upload : </label>
<input type="file" name="myfile">
<br>
<input type="submit" name="" value="Upload the file">
</form>
就是这样。现在你应该可以使用 CogiUpload 了!
本地化
目前只支持英文。
文档
完整的文档位于 doc 文件夹中。
测试
在 test 文件夹中有一个测试页面,可以尝试该组件。
贡献
如果您有任何想法或建议,请通过电子邮件发送给 Philippe
变更日志
请参阅 变更日志。
历史
- 最初,CogiUpload 是一个PHP库中的过程化函数。
- 然后,这个函数变成了一个类。
- 现在,CogiUpload 位于 BitBucket 仓库中。
- 带有 Readme 文件和一个 PhpDocumentor 文件夹。
- 而且,还有 PSR 文件夹来查看代码质量 ;-)