Exemplo n.º 1
0
/**
 * 上传文件
 * @param array $fileInfo
 * @param string $path
 * @param array $allowExt
 * @param int $maxSize
 * @return string
 */
function uploadFileo($fileInfo, $path, $allowExt = array("ini"), $maxSize = 10485760)
{
    //判断错误号
    if ($fileInfo['error'] == UPLOAD_ERR_OK) {
        //文件是否是通过HTTP POST方式上传上来的
        if (is_uploaded_file($fileInfo['tmp_name'])) {
            //上传文件的文件名,只允许上传jpeg|jpg、png、gif、txt的文件
            //$allowExt=array("gif","jpeg","jpg","png","txt");
            $ext = getExtc($fileInfo['name']);
            $uniqid = getUniqidNamec();
            $destination = $path . "/" . pathinfo($fileInfo['name'], PATHINFO_FILENAME) . "_" . $uniqid . "." . $ext;
            if (!in_array($ext, $allowExt)) {
                if ($fileInfo['size'] <= $maxSize) {
                    if (move_uploaded_file($fileInfo['tmp_name'], $destination)) {
                        $mes = "文件上传成功";
                    } else {
                        $mes = "文件移动失败";
                    }
                } else {
                    $mes = "文件过大";
                }
            } else {
                $mes = "非法文件类型";
            }
        } else {
            $mes = "文件不是通过HTTP POST方式上传上来的";
        }
    } else {
        switch ($fileInfo['error']) {
            case 1:
                $mes = "超过了配置文件的大小";
                break;
            case 2:
                $mes = "超过了表单允许接收数据的大小";
                break;
            case 3:
                $mes = "文件部分被上传";
                break;
            case 4:
                $mes = "没有文件被上传";
                break;
        }
    }
    return $mes;
}
Exemplo n.º 2
0
require_once '../include/file_operation.php';
require_once '../include/common_function.php';
$public_function = new public_function();
$photo_album = $_GET['photo_album'];
$photo_name0 = $_GET['photo_name'];
$photo_name = explode(',', $photo_name0);
$photo_createdate = CURRENT_TIME;
$blog_userid = $_SESSION['UID'];
$url = str_replace(" ", "", $_GET['url']);
$page = str_replace(" ", "", $_GET['page']);
for ($i = 0; $i < count($photo_name); $i++) {
    $photo_path = "../plugins/upload/server/php/files/" . $photo_name[$i];
    $photo_thumbnail = "../plugins/upload/server/php/files/thumbnail/" . $photo_name[$i];
    $date = date("Ymdhis", time());
    $newvar = $date . $blog_userid;
    $unique = getUniqidNamec();
    $ext1 = getExtc($photo_path);
    $ext2 = getExtc($photo_thumbnail);
    $newname1 = $newvar . "_" . $unique . "." . $ext1;
    $newname2 = $newvar . "_" . $unique . "." . $ext2;
    $photo_pathtoc = "../plugins/upload/server/php/files/" . $newvar . "_" . $unique . "." . $ext1;
    $photo_thumbnailtoc = "../plugins/upload/server/php/files/thumbnail/" . $newvar . "_" . $unique . "." . $ext2;
    $rename1 = renameFileo($photo_path, $newname1);
    $rename2 = renameFileo($photo_thumbnail, $newname2);
    copyFileo($photo_pathtoc, "upload");
    copyFileo($photo_thumbnailtoc, "upload/thumbnail");
    delFileo($photo_pathtoc);
    delFileo($photo_thumbnailtoc);
    $photo_pathnew = "upload/" . $newname1;
    $photo_thumbnailnew = "upload/thumbnail/" . $newname2;
    $sql = "insert into blog_photo(photo_name,photo_createdate,photo_path,photo_author,photo_album,photo_thumbnail) \n\t\t\tvalues('{$photo_name[$i]}','{$photo_createdate}','{$photo_pathnew}','{$blog_userid}','{$photo_album}','{$photo_thumbnailnew}')";