当前位置: 首页>>代码示例>>PHP>>正文


PHP Upload::SaveFile方法代码示例

本文整理汇总了PHP中Upload::SaveFile方法的典型用法代码示例。如果您正苦于以下问题:PHP Upload::SaveFile方法的具体用法?PHP Upload::SaveFile怎么用?PHP Upload::SaveFile使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Upload的用法示例。


在下文中一共展示了Upload::SaveFile方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: markdown_upload_ajax_image

function markdown_upload_ajax_image()
{
    global $zbp;
    $xhr = array('error' => "", 'url' => "");
    foreach ($_FILES as $key => $value) {
        if ($_FILES[$key]['error'] == 0) {
            if (is_uploaded_file($_FILES[$key]['tmp_name'])) {
                $tmp_name = $_FILES[$key]['tmp_name'];
                $name = $_FILES[$key]['name'];
                $upload = new Upload();
                $upload->Name = $_FILES[$key]['name'];
                $upload->SourceName = $_FILES[$key]['name'];
                $upload->MimeType = $_FILES[$key]['type'];
                $upload->Size = $_FILES[$key]['size'];
                $upload->AuthorID = $zbp->user->ID;
                if (!$upload->CheckExtName()) {
                    $xhr['error'] = $this->lang['error'][26];
                }
                if (!$upload->CheckSize()) {
                    $xhr['error'] = $this->lang['error'][27];
                }
                $upload->SaveFile($_FILES[$key]['tmp_name']);
                $upload->Save();
            }
        }
    }
    if (isset($upload)) {
        CountMemberArray(array($upload->AuthorID), array(0, 0, 0, +1));
        $xhr['url'] = $upload->Url;
    }
    echo json_encode($xhr);
}
开发者ID:zblogcn,项目名称:zblogphp,代码行数:32,代码来源:include.php

示例2: PostUpload

function PostUpload()
{
    global $zbp;
    foreach ($_FILES as $key => $value) {
        if ($_FILES[$key]['error'] == 0) {
            if (is_uploaded_file($_FILES[$key]['tmp_name'])) {
                $tmp_name = $_FILES[$key]['tmp_name'];
                $name = $_FILES[$key]['name'];
                $upload = new Upload();
                $upload->Name = $_FILES[$key]['name'];
                $upload->SourceName = $_FILES[$key]['name'];
                $upload->MimeType = $_FILES[$key]['type'];
                $upload->Size = $_FILES[$key]['size'];
                $upload->AuthorID = $zbp->user->ID;
                if (!$upload->CheckExtName()) {
                    $zbp->ShowError(26);
                }
                if (!$upload->CheckSize()) {
                    $zbp->ShowError(27);
                }
                $upload->SaveFile($_FILES[$key]['tmp_name']);
                $upload->Save();
            }
        }
    }
    if (isset($upload)) {
        CountMemberArray(array($upload->AuthorID));
    }
}
开发者ID:jdjjdkdkdm,项目名称:zblogphp,代码行数:29,代码来源:c_system_event.php

示例3: alert

    // if (empty($ext_arr[$dir_name])) {
    // 	alert("目录名不正确。");
    // }
    //获得文件扩展名
    $temp_arr = explode(".", $file_name);
    $file_ext = array_pop($temp_arr);
    $file_ext = trim($file_ext);
    $file_ext = strtolower($file_ext);
    //检查扩展名
    if (in_array($file_ext, $ext_arr) === false) {
        alert("上传文件扩展名是不允许的扩展名。\n只允许" . implode(",", $ext_arr) . "格式。");
    }
    $upload = new Upload();
    $upload->Name = date("YmdHis") . '_' . rand(10000, 99999) . '.' . $file_ext;
    $upload->SourceName = $file_name;
    $upload->MimeType = $_FILES['imgFile']['type'];
    $upload->Size = $file_size;
    $upload->AuthorID = $zbp->user->ID;
    $upload->SaveFile($tmp_name);
    $upload->Save();
    $file_url = $upload->Url;
    header('Content-type: text/html; charset=UTF-8');
    echo json_encode(array('error' => 0, 'url' => $file_url));
    exit;
}
function alert($msg)
{
    header('Content-type: text/html; charset=UTF-8');
    echo json_encode(array('error' => 1, 'message' => $msg));
    exit;
}
开发者ID:zblogcn,项目名称:zblogphp,代码行数:31,代码来源:upload_json.php

示例4: upFile

 /**
  * 上传文件的主处理方法
  * @return mixed
  */
 private function upFile()
 {
     global $zbp;
     $file = $this->file = $_FILES[$this->fileField];
     if (!$file) {
         $this->stateInfo = $this->getStateInfo("ERROR_FILE_NOT_FOUND");
         return;
     }
     if ($this->file['error']) {
         $this->stateInfo = $this->getStateInfo($file['error']);
         return;
     } else {
         if (!is_uploaded_file($file['tmp_name'])) {
             $this->stateInfo = $this->getStateInfo("ERROR_TMPFILE");
             return;
         }
     }
     $this->oriName = $file['name'];
     $this->fileSize = $file['size'];
     $this->fileType = $this->getFileExt();
     $this->fullName = $this->getFullName();
     $this->filePath = $this->getFilePath();
     $this->fileName = $this->getFileName();
     $dirname = dirname($this->filePath);
     //检查文件大小是否超出限制
     if (!$this->checkSize()) {
         $this->stateInfo = $this->getStateInfo("ERROR_SIZE_EXCEED");
         return;
     }
     //检查是否不允许的文件格式
     if (!$this->checkType()) {
         $this->stateInfo = $this->getStateInfo("ERROR_TYPE_NOT_ALLOWED");
         return;
     }
     $upload = new Upload();
     $upload->Name = $this->fileName;
     $upload->SourceName = $file['name'];
     $upload->MimeType = $file['type'];
     $upload->Size = $this->fileSize;
     $upload->AuthorID = $zbp->user->ID;
     if (!$upload->SaveFile($file['tmp_name'])) {
         $this->stateInfo = $this->getStateInfo("ERROR_FILE_MOVE");
         return;
     }
     $upload->Save();
     $this->fullName = $upload->Url;
     $this->stateInfo = $this->stateMap[0];
 }
开发者ID:ijustyce,项目名称:zblogphp,代码行数:52,代码来源:Uploader.class.php

示例5: PostUpload

/**
 * 附件上传
 */
function PostUpload()
{
    global $zbp;
    foreach ($_FILES as $key => $value) {
        if ($_FILES[$key]['error'] == 0) {
            if (is_uploaded_file($_FILES[$key]['tmp_name'])) {
                $upload = new Upload();
                $upload->Name = $_FILES[$key]['name'];
                if (GetVars('auto_rename', 'POST') == 'on' || GetVars('auto_rename', 'POST') == true) {
                    $temp_arr = explode(".", $upload->Name);
                    $file_ext = strtolower(trim(array_pop($temp_arr)));
                    $upload->Name = date("YmdHis") . time() . rand(10000, 99999) . '.' . $file_ext;
                }
                $upload->SourceName = $_FILES[$key]['name'];
                $upload->MimeType = $_FILES[$key]['type'];
                $upload->Size = $_FILES[$key]['size'];
                $upload->AuthorID = $zbp->user->ID;
                //检查同月重名
                $d1 = date('Y-m-01', time());
                $d2 = date('Y-m-d', strtotime(date('Y-m-01', time()) . ' +1 month -1 day'));
                $d1 = strtotime($d1);
                $d2 = strtotime($d2);
                $w = array();
                $w[] = array('=', 'ul_Name', $upload->Name);
                $w[] = array('>=', 'ul_PostTime', $d1);
                $w[] = array('<=', 'ul_PostTime', $d2);
                $uploads = $zbp->GetUploadList('*', $w);
                if (count($uploads) > 0) {
                    $zbp->ShowError(28, __FILE__, __LINE__);
                }
                if (!$upload->CheckExtName()) {
                    $zbp->ShowError(26, __FILE__, __LINE__);
                }
                if (!$upload->CheckSize()) {
                    $zbp->ShowError(27, __FILE__, __LINE__);
                }
                $upload->SaveFile($_FILES[$key]['tmp_name']);
                $upload->Save();
            }
        }
    }
    if (isset($upload)) {
        CountMemberArray(array($upload->AuthorID), array(0, 0, 0, +1));
    }
}
开发者ID:zblogcn,项目名称:zblogphp,代码行数:48,代码来源:c_system_event.php

示例6: import_upload

function import_upload()
{
    global $t, $db, $config, $vars;
    $title = "Import. Step 1 of 3 ";
    if (!$_SESSION['import_file_name']) {
        $_SESSION['import_file_name'] = array();
    }
    if (!$vars['use_uploaded'] && $vars['action'] == 'upload') {
        $upload = new Upload($config['root_dir'] . "/data");
        if (!$upload->Error) {
            $upload->SaveFile();
            if (!$upload->Error) {
                $file_for_import = $upload->UploadedFiles[0]['fullpath'];
                if (is_array($_SESSION['import_file_name']) && !in_array($file_for_import, $_SESSION['import_file_name'])) {
                    $_SESSION['import_file_name'][] = $file_for_import;
                }
                $do_next = 1;
            } else {
                $err[] = $upload->Error;
            }
        } else {
            $err[] = $upload->Error;
        }
    } elseif ($vars['use_uploaded'] && $vars['action'] == 'upload') {
        if ($vars['use_uploaded'] == 'imp.csv' && @is_file($config['root_dir'] . "/admin/imp.csv") && @is_readable($config['root_dir'] . "/admin/imp.csv")) {
            $file_for_import = $config['root_dir'] . "/admin/imp.csv";
            if (is_array($_SESSION['import_file_name']) && !in_array($file_for_import, $_SESSION['import_file_name'])) {
                $_SESSION['import_file_name'][] = $file_for_import;
            }
            $do_next = 1;
        } elseif (@is_file($config['root_dir'] . "/data/" . basename($vars['use_uploaded']))) {
            $file_for_import = $config['root_dir'] . "/data/" . basename($vars['use_uploaded']);
            if (is_array($_SESSION['import_file_name']) && !in_array($file_for_import, $_SESSION['import_file_name'])) {
                $_SESSION['import_file_name'][] = $file_for_import;
            }
            $do_next = 1;
        } elseif (@is_file($config['root_dir'] . "/" . basename($vars['use_uploaded']))) {
            $file_for_import = $config['root_dir'] . "/" . basename($vars['use_uploaded']);
            if (is_array($_SESSION['import_file_name']) && !in_array($file_for_import, $_SESSION['import_file_name'])) {
                $_SESSION['import_file_name'][] = $file_for_import;
            }
            $do_next = 1;
        } elseif (@is_file($vars['use_uploaded'])) {
            $file_for_import = $vars['use_uploaded'];
            if (is_array($_SESSION['import_file_name']) && !in_array($file_for_import, $_SESSION['import_file_name'])) {
                $_SESSION['import_file_name'][] = $file_for_import;
            }
            $do_next = 1;
        } else {
            $err[] = "Import file not found.";
        }
    }
    if (!$vars['delim'] && $_SESSION['import_file_delim']) {
        $vars['delim'] = $_SESSION['import_file_delim'];
    }
    if ($vars['delim']) {
        $_SESSION['import_file_delim'] = $vars['delim'];
    }
    if (!$err && $do_next) {
        if (!($f = @fopen($file_for_import, 'r'))) {
            $err[] = "Cannot open file '{$file_for_import}' for import";
            @fclose($f);
        } else {
            $line = fgets($f, 4096);
            if (preg_match("/\n/", $line) && preg_match("/\r/", $line)) {
                $l = $line;
            } elseif (preg_match("/\r/", $line)) {
                $l = preg_split("/\r/", $line);
                $l = $l[0];
            } else {
                $l = $line;
            }
            $l = explode($vars['delim'], $l);
            @fclose($f);
            if (count($l) >= 2) {
                import_select_fields($file_for_import, $vars['delim'], $l);
            } else {
                $err[] = "Fields not found or number of fields < 2";
            }
        }
    }
    if ($err) {
        $t->assign('error', $err);
        $title .= "Error : " . $err[0];
    } else {
        $title .= ": Select import file";
    }
    $t->assign('delim', $vars['delim'] ? $vars['delim'] : $_SESSION['import_file_delim']);
    $t->assign('previous_files', $_SESSION['import_file_name']);
    if (count($_SESSION['import_file_name']) == 1) {
        $t->assign('preselected_file', $_SESSION['import_file_name'][0]);
    }
    $t->assign('title', $title);
    $t->display('admin/import_upload.html');
}
开发者ID:subashemphasize,项目名称:test_site,代码行数:95,代码来源:import.php


注:本文中的Upload::SaveFile方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。