PHP code example of aileshe / upload
1. Go to this page and download the library: Download aileshe/upload library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
aileshe / upload example snippets
$upload = new \Dj\Upload();
$filelist = $upload->save('./upload');
if(is_array($filelist)){
# 返回数组,文件就上传成功了
print_r($filelist);
}else{
# 如果返回负整数(int)就是发生错误了
$error_msg = [-1=>'上传失败',-2=>'文件存储路径不合法',-3=>'上传非法格式文件',-4=>'文件大小不合符规定',-5=>'token验证错误'];
echo $error_msg[$filelist];
}
$upload = new \Dj\Upload();
$upload->token('FFFX123456'); # 设置 token
$filelist = $upload->save('./upload');
# 或
$upload = new \Dj\Upload();
$filelist = $upload->token('FFFX123456')->save('./upload');
$upload = new \Dj\Upload();
$filelist = $upload->save('./upload', [
'ext'=>'jpg,jpeg,png,gif'
]);
# 或
$upload = new \Dj\Upload();
$filelist = $upload->save('./upload', [
'ext'=>['jpg','jpeg','png','gif']
]);
$upload = new \Dj\Upload();
$filelist = $upload->save('./upload', [
'mime'=>'image/jpeg,image/gif,image/bmp'
]);
# 或
$upload = new \Dj\Upload();
$filelist = $upload->save('./upload', [
'mime'=>['image/jpeg','image/gif','image/bmp']
]);