getFileName() protected method

获取新的文件名
protected getFileName ( )
 /**
  * Goes through the array of files and processes them accordingly.
  * The result is an array of the appropiate Resource class that has been
  * created using the ResourceFactory class.
  *
  * @return An array of Upload objects that have already been moved to a safer
  * location.
  */
 function process($destinationFolder)
 {
     // first, check if the upload feature is available
     $config =& Config::getConfig();
     if (!$config->getValue("uploads_enabled")) {
         return FILE_UPLOADS_NOT_ENABLED;
     }
     // array used to store the files that have already been saved
     $uploads = array();
     if ($destinationFolder[strlen($destinationFolder - 1)] != "/") {
         $destinationFolder .= "/";
     }
     foreach ($this->_files as $file) {
         $upload = new FileUpload($file);
         $fileName = $upload->getFileName();
         if ($this->my_move_uploaded_file($upload->getTmpName(), $destinationFolder . $fileName)) {
             $upload->setFolder($destinationFolder);
             $upload->setError(0);
         } else {
             $upload->setError(1);
         }
         array_push($uploads, $upload);
     }
     return $uploads;
 }
function upload()
{
    $path = "./uploads/";
    //设置图片上传路径
    $up = new FileUpload($path);
    //创建文件上传类对象
    if ($up->upload('pic')) {
        //上传图片
        $filename = $up->getFileName();
        //获取上传后的图片名
        $img = new Image($path);
        //创建图像处理类对象
        $img->thumb($filename, 300, 300, "");
        //将上传的图片都缩放至在300X300以内
        $img->thumb($filename, 80, 80, "icon_");
        //缩放一个80x80的图标,使用icon_作前缀
        $img->watermark($filename, "logo.gif", 5, "");
        //为上传的图片加上图片水印
        return array(true, $filename);
        //如果成功返回成功状态和图片名称
    } else {
        return array(false, $up->getErrorMsg());
        //如果失败返回失败状态和错误消息
    }
}
 /**
  * installs an uploaded template
  */
 function _performUploadTemplate()
 {
     // handle the uploaded file
     $files = HttpVars::getFiles();
     $uploads = new FileUploads($files);
     if (count($files) == 0 || $files["templateFile"]["name"] == "") {
         $this->_view = new AdminTemplatedView($this->_blogInfo, "newglobaltemplate");
         $this->_view->setValue("templateFolder", TemplateSetStorage::getBaseTemplateFolder());
         $this->_view->setErrorMessage($this->_locale->tr("error_must_upload_file"));
         $this->setCommonData();
         return false;
     }
     $config =& Config::getConfig();
     $tmpFolder = $config->getValue('temp_folder');
     // move it to the temporary folder
     $result = $uploads->process($tmpFolder);
     // and from there, unpack it
     $upload = new FileUpload($files['templateFile']);
     $templateSandbox = new TemplateSandbox();
     $valid = $templateSandbox->checkTemplateSet($upload->getFileName(), $tmpFolder . '/');
     if ($valid < 0) {
         $this->_view = new AdminSiteTemplatesListView($this->_blogInfo);
         $this->_view->setErrorMessage($this->_checkTemplateSandboxResult($valid));
         $this->setCommonData();
         return false;
     }
     // the template was ok, so then we can proceed and move it to the main
     // template folder, add it to our array of templates
     //
     // :KLUDGE:
     //
     // maybe we should simply move the files rather than unpacking the whole
     // thing again, but this indeed makes things easier! ;)
     $unpacker = new Unpacker();
     $templateFolder = $config->getValue('template_folder');
     $fileToUnpack = $tmpFolder . '/' . $upload->getFileName();
     if (!$unpacker->unpack($fileToUnpack, $templateFolder)) {
         $this->_view = new AdminSiteTemplatesListView($this->_blogInfo);
         $tf = new Textfilter();
         $this->_view->setErrorMessage($this->_locale->pr('error_installing_template', $tf->filterAllHtml($upload->getFileName())));
         $this->setCommonData();
         return false;
     }
     // if the template set was installed ok in the template folder, we can record
     // it as a valid set
     $ts = new TemplateSetStorage();
     $fileParts = explode(".", $upload->getFileName());
     $templateName = $fileParts[0];
     $ts->addTemplate($templateName);
     $this->_view = new AdminSiteTemplatesListView($this->_blogInfo);
     $this->_view->setSuccessMessage($this->_locale->pr('template_installed_ok', $templateName));
     $this->setCommonData();
     return true;
 }
示例#4
0
 public function preform()
 {
     $uploadFile = new FileUpload();
     $uploadFile->set("maxsize", 2000000);
     $uploadFile->set("allowtype", array("gif", "png", "jpg", "jpeg"));
     $uploadFile->set("israndname", true);
     if ($this->params['safe']['type'] == "addArticle") {
         $path = "../uploadfile/article/" . $this->params['safe']['fenlei_id'] . "/";
         $uploadFile->set("path", $path);
         if ($uploadFile->upload('fm_img')) {
             $data = array('uid' => 1, 'title' => $this->params['safe']['title'], 'contents' => $this->params['safe']['contents'], 'fenlei_id' => $this->params['safe']['fenlei_id'], 'fm_img' => $path . $uploadFile->getFileName(), 'time' => time());
             $DaoArticle = new DaoArticle();
             $DaoArticle->insertArticle($data);
         } else {
             //获取上传失败以后的错误提示
             throw new Exception('error_file_upload', $uploadFile->getErrorMsg());
         }
     } elseif ($this->params['safe']['type'] == "addUser") {
         $path = "../uploadfile/user_img/" . $this->params['safe']['user_name'] . "/";
         $uploadFile->set("path", $path);
         if ($uploadFile->upload('user_img')) {
             $data = array('user_name' => $this->params['safe']['user_name'], 'user_nickname' => $this->params['safe']['user_nickname'], 'user_password' => md5($this->params['safe']['password']), 'user_qm' => "这家伙还没写签名呢!", 'user_img' => $path . $uploadFile->getFileName(), 'user_inTime' => time());
             $DaoUser = new DaoUser();
             $DaoUser->addUser($data);
         } else {
             //获取上传失败以后的错误提示
             throw new Exception('error_file_upload', $uploadFile->getErrorMsg());
         }
     } elseif ($this->params['safe']['type'] == "addfenlei") {
         $path = "../uploadfile/Fenlei/";
         $uploadFile->set("path", $path);
         if ($uploadFile->upload('fenlei_img')) {
             $data = array('name' => $this->params['safe']['name'], 'time' => time(), 'fenlei_img' => $path . $uploadFile->getFileName());
             $DaoFenlei = new DaoFenlei();
             $DaoFenlei->addFenlei($data);
         }
     }
 }
示例#5
0
文件: add.php 项目: ahmatjan/manage
{
    //生成文件
    $File = new FileUtil();
    $File->writetofile(BASE_PATH . 'upload/webstyle/public/' . $type . '/' . $title . '.' . $type, $content);
    return $codeFilePath = '/manage/upload/webstyle/public/' . $type . '/' . $title . '.' . $type;
}
if (isset($_POST['category']) && $_POST['category'] == 'code') {
    $up = new FileUpload();
    //设置属性(上传的位置, 大小, 类型, 名是是否要随机生成)
    $up->set("path", "../../upload/webstyle/public/" . $_POST['code_type']);
    $up->set("maxsize", 2000000);
    $up->set("allowtype", array("gif", "png", "jpg", "jpeg", 'css', 'js'));
    $up->set("israndname", false);
    //使用对象中的upload方法, 就可以上传文件, 方法需要传一个上传表单的名子 pic, 如果成功返回true, 失败返回false
    if ($up->upload("file")) {
        var_dump($up->getFileName());
        $file_path_code = '/manage/upload/webstyle/public/' . $_POST['code_type'] . '/' . $up->getFileName();
    } else {
        echo '<pre>';
        //获取上传失败以后的错误提示
        var_dump($up->getErrorMsg());
        echo '</pre>';
    }
    $db = new DB();
    $data['id'] = "";
    $data['title'] = $_POST['code_title'];
    //$data['content'] = $_POST['code_content'];
    $data['type'] = $_POST['code_type'];
    $data['file_path'] = $file_path_code;
    $data['is_public'] = 1;
    $db->insert('webstyle_code', $data);
示例#6
0
<?php

require 'Uploader.php';
//try to get the directory from the request
$dir = htmlspecialchars($_GET["dir"]);
//if it is null
if ($dir === null || $dir === "") {
    echo json_encode(array('success' => false, 'msg' => $Upload->getErrorMsg()));
    return;
} else {
    if ($dir === "files") {
        $upload_dir = '././Content/files/';
        //$valid_extensions = array('adi', 'txt', 'cabrillo.txt', 'log', 'cbr');
    } else {
        echo json_encode(array('success' => false, 'msg' => $Upload->getErrorMsg()));
        return;
    }
}
$Upload = new FileUpload('uploadfile');
$ext = $Upload->getExtension();
// Get the extension of the uploaded file
$time = time();
$Upload->newFileName = $time . '.' . $ext;
//$result = $Upload->handleUpload($upload_dir, $valid_extensions);
$result = $Upload->handleUpload($upload_dir);
if (!$result) {
    echo json_encode(array('success' => false, 'msg' => $Upload->getErrorMsg()));
} else {
    echo json_encode(array('success' => true, 'file' => $Upload->getFileName(), 'timestamp' => $time));
}
示例#7
0
 if ($arr_request_headers['Authorization'] != CSRF_KEY) {
     echo "Wrong access key";
     exit;
 }
 require_once _TRACK_SHOW_COMMON_PATH . '/lib/uploader/uploader.php';
 $upload_dir = ini_get('upload_tmp_dir') ? ini_get('upload_tmp_dir') : sys_get_temp_dir();
 $valid_extensions = array('xlsx');
 $Upload = new FileUpload('ajax_upload_offers');
 $Upload->newFileName = 'offers.xlsx';
 $result = $Upload->handleUpload($upload_dir, $valid_extensions);
 if (!$result) {
     echo json_encode(array('success' => false, 'msg' => $Upload->getErrorMsg()));
 } else {
     require_once _TRACK_SHOW_COMMON_PATH . '/lib/excel-reader/excel_reader.php';
     require_once _TRACK_SHOW_COMMON_PATH . '/lib/excel-reader/SpreadsheetReader.php';
     $reader = new SpreadsheetReader($upload_dir . '/' . $Upload->getFileName());
     $i = 0;
     foreach ($reader as $xls_row) {
         // Skip row with column names
         if ($i++ == 0) {
             continue;
         }
         $category_id = 0;
         // Category is set
         if (isset($xls_row[3])) {
             $category_name = trim(str_replace(array("\r\n", "\r", "\n", "\t"), '', $xls_row[3]));
             if ($category_name != '') {
                 // Check if we already have this category
                 $sql = "select id, status from tbl_links_categories_list where category_caption='" . _str($category_name) . "'";
                 $result = mysql_query($sql);
                 $row = mysql_fetch_assoc($result);
示例#8
0
$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>
 function _performUploadLocale()
 {
     // since we are here, the file name was validated to be ok, so we can
     // continue with the operation
     $files = HttpVars::getFiles();
     $uploads = new FileUploads($files);
     $this->_view = new AdminSiteLocalesListView($this->_blogInfo);
     // we can first of all move the file to the destionation folder
     $result = $uploads->process($this->_config->getValue("locale_folder"));
     // the only thing that can happen is that the file was not correctly saved
     if ($result[0]->getError() != 0) {
         $this->_view->setErrorMessage($this->_locale->tr("error_saving_locale"));
         return false;
     }
     // and once it's there, we can do as if we were adding a locale code
     $upload = new FileUpload($files["localeFile"]);
     $res = preg_match(REGEXP_VALID_LOCALE, $upload->getFileName(), $matches);
     $localeCode = $matches[1];
     // add the file to the list of locales
     $locales = new Locales();
     $locales->addLocale($localeCode);
     $this->_view->setSuccessMessage($this->_locale->pr("locale_added_ok", $localeCode));
     return true;
 }
示例#10
0
文件: dashboard.php 项目: ram-1501/rs
 function upload_car($id = 0)
 {
     $this->load->library('FileUpload');
     $upload_dir = 'assets/uploads/cars/';
     $uploader = new FileUpload('uploadfile');
     // Handle the upload
     $result = $uploader->handleUpload($upload_dir);
     if (!$result) {
         exit(json_encode(array('success' => false, 'msg' => $uploader->getErrorMsg())));
     }
     $update = array('img_name' => $uploader->getFileName());
     $this->car_model->update(array('id' => $id), $update);
     echo json_encode(array('success' => true, 'fname' => $uploader->getFileName()));
     exit;
 }
示例#11
0
 function upload($path = '')
 {
     $path = trim($path, '/');
     $folder = $this->BasePath . $path;
     if (!is_dir($folder)) {
         if (is_gb2312($path)) {
             $path = iconv('gb2312', 'utf-8', $path);
         }
         throw new Exception("文件夹 '{$path}' 不存在。");
     }
     if (!file_exists('fileupload.class.php')) {
         throw new Exception("没找到文件'fileupload.class.php, 无法上传文件。");
     }
     require_once 'fileupload.class.php';
     $up = new FileUpload();
     //设置属性(上传的位置, 大小, 类型, 名是是否要随机生成)
     $up->set("path", $folder);
     $up->set("maxsize", 8 * 1024 * 1024);
     if (empty($this->allowType) || $this->allowType == '*') {
         $up->set("allowtype", explode(',', $this->allType));
     } else {
         $up->set("allowtype", explode(',', $this->allowType));
     }
     $up->set("israndname", false);
     if (!$up->upload("file")) {
         $errors = $up->getErrorMsg();
         if (is_array($errors)) {
             $errors = implode("\n", $errors);
         }
         throw new Exception($errors);
     } else {
         $filenames = $up->getFileName();
         if (is_string($filenames)) {
             $filenames[] = $filenames;
         }
         foreach ($filenames as $key => $value) {
             $filename = iconv('utf-8', 'gb2312', $value);
             if (true === @rename($folder . '/' . $value, $folder . '/' . $filename)) {
                 $filenames[$key] = $filename;
             }
         }
     }
     return $up->getFileName();
 }
示例#12
0
<?php

require '../assets/plugins/Simple-Ajax-Uploader/extras/Uploader.php';
$upload_dir = 'uploads';
$valid_extensions = array('pdf');
$Upload = new FileUpload('fileatt');
$result = $Upload->handleUpload($upload_dir, $valid_extensions);
if (!$result) {
    echo json_encode(array('success' => false, 'msg' => $Upload->getErrorMsg()));
} else {
    echo json_encode(array('success' => true, 'file' => $Upload->getFileName()));
}
示例#13
0
<?php

include '../../../../../../wp-load.php';
require dirname(__FILE__) . '/php/Uploader.php';
//
$upload_dir = dirname(dirname(dirname(dirname(dirname(dirname(__FILE__)))))) . '/uploads/ssuploader/';
if (!is_dir($upload_dir)) {
    mkdir($upload_dir);
}
$uploader = new FileUpload('uploadfile');
$uploader->newFileName = sanitize_file_name($uploader->getFileName()) . '_' . rand(0, 10) . '.' . $uploader->getExtension();
$result = $uploader->handleUpload($upload_dir);
//
switch ($_GET['uploadType']) {
    case 'cv':
        if (!$result) {
            exit(json_encode(array('success' => FALSE, 'msg' => $uploader->getErrorMsg())));
        } else {
            ///
            $cv_url = SURL . '/wp-content/' . explode('wp-content', $uploader->getSavedFile())[1];
            $attach_id = xsUTL::add_image($cv_url);
            if ($attach_id > 0) {
                echo json_encode(array('status' => TRUE, 'id' => $attach_id));
            } else {
                echo json_encode(array('status' => TRUE, 'msg' => 'File Upload Failed.Please try again'));
            }
        }
        die;
        break;
}
// Directory where we're storing uploaded images
示例#14
0
 function upload($path = '')
 {
     $path = $this->BaseUrl . '/' . trim($path, '/');
     if (!is_dir($path)) {
         $data['error'] = 'Folder ' . $path . ' does not exist.';
         return $data;
     }
     $up = new FileUpload();
     //设置属性(上传的位置, 大小, 类型, 名是是否要随机生成)
     $up->set("path", $path);
     $up->set("maxsize", 8 * 1024 * 1024);
     if (!empty($this->allowType) && $this->allowType != '*') {
         $up->set("allowtype", explode(',', $this->allowType));
     }
     $up->set("israndname", false);
     if ($up->upload("upfile")) {
         return $up->getFileName();
     } else {
         $data['error'] = $up->getErrorMsg();
     }
     /**/
     return $data;
 }
 function _performUploadTemplate()
 {
     // get the temporary folder
     $config =& Config::getConfig();
     $tmpFolder = $config->getValue("temp_folder");
     // move it to the temporary folder
     $files = HttpVars::getFiles();
     if (count($files) == 0 || $files["templateFile"]["name"] == "") {
         $this->_view = new AdminTemplatedView($this->_blogInfo, "newblogtemplate");
         $this->_view->setValue("templateFolder", TemplateSetStorage::getBlogBaseTemplateFolder($this->_blogInfo->getId()));
         $this->_view->setErrorMessage($this->_locale->tr("error_must_upload_file"));
         $this->setCommonData();
         return false;
     }
     $uploads = new FileUploads($files);
     $result = $uploads->process($tmpFolder);
     if ($result < 0) {
         $this->_view = new AdminBlogTemplateSetsListView($this->_blogInfo);
         $this->_view->setErrorMessage($this->_locale->tr("error_uploads_disabled"));
         $this->setCommonData();
         return false;
     }
     $upload = new FileUpload($files["templateFile"]);
     // and make it go through the template sandbox to check if
     // we're dealing with a 'healthy' file
     $templateSandbox = new TemplateSandbox();
     $valid = $templateSandbox->checkTemplateSet($upload->getFileName(), $tmpFolder . "/");
     if ($valid < 0) {
         $this->_view = new AdminBlogTemplateSetsListView($this->_blogInfo);
         $this->_view->setErrorMessage(AdminAddTemplateAction::_checkTemplateSandboxResult($valid));
         $this->setCommonData();
         return false;
     }
     //
     // :KLUDGE:
     //
     // maybe we should simply move the files rather than unpacking the whole
     // thing again, but this indeed makes things easier! ;)
     //
     // since it is a local template, the path has to be $template_folder/blog_x/$templateName
     $ts = new TemplateSetStorage();
     $blogTemplateFolder = $ts->createBlogTemplateFolder($this->_blogInfo->getId());
     // it should be there now... we can continue
     $destFolder = $blogTemplateFolder . "/";
     $unpacker = new Unpacker();
     if (!$unpacker->unpack($tmpFolder . "/" . $upload->getFileName(), $destFolder)) {
         $this->_view = new AdminBlogTemplateSetsListView($this->_blogInfo);
         $this->_view->setErrorMessage($this->_locale->tr("error_installing_template"));
         $this->setCommonData();
         // remove the file before returning!
         File::delete($tmpFolder . "/" . $upload->getFileName());
         return false;
     }
     // if the template set was installed ok in the template folder, we can record
     // it as a valid set
     $fileParts = explode(".", $upload->getFileName());
     $templateName = $fileParts[0];
     $ts->addTemplate($templateName, $this->_blogInfo->getId());
     // remove the file
     File::delete($tmpFolder . "/" . $upload->getFileName());
     $this->_view = new AdminBlogTemplateSetsListView($this->_blogInfo);
     $this->_view->setSuccessMessage($this->_locale->pr("template_installed_ok", $templateName));
     $this->setCommonData();
     return true;
 }