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


PHP Upload::uploadFiles方法代码示例

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


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

示例1: uploadFile

 /**
  * Saves the uploaded file and returns the file info.
  *
  * @return stdClass
  * @throws Exception
  */
 public function uploadFile()
 {
     try {
         $uploadManager = new Upload();
         $uploadedFiles = $uploadManager->uploadFiles($_FILES);
     } catch (Exception $e) {
         //            Log::doLog( $e->getMessage() );
         throw new Exception($e->getMessage(), -8);
     }
     return $this->file = $uploadedFiles;
 }
开发者ID:indynagpal,项目名称:MateCat,代码行数:17,代码来源:TMSService.php

示例2: handleIconUpload

/**
 * Upload new topic icon, replaces previous icon if one exists
 *
 * @param    string $tid ID of topic to prepend to filename
 * @return   string          filename of new photo (empty = no new photo)
 */
function handleIconUpload($tid)
{
    global $_CONF, $_TABLES, $LANG27;
    $upload = new Upload();
    if (!empty($_CONF['image_lib'])) {
        if ($_CONF['image_lib'] == 'imagemagick') {
            // Using imagemagick
            $upload->setMogrifyPath($_CONF['path_to_mogrify']);
        } elseif ($_CONF['image_lib'] == 'netpbm') {
            // using netPBM
            $upload->setNetPBM($_CONF['path_to_netpbm']);
        } elseif ($_CONF['image_lib'] == 'gdlib') {
            // using the GD library
            $upload->setGDLib();
        }
        $upload->setAutomaticResize(true);
        if (isset($_CONF['debug_image_upload']) && $_CONF['debug_image_upload']) {
            $upload->setLogFile($_CONF['path'] . 'logs/error.log');
            $upload->setDebug(true);
        }
        if (isset($_CONF['jpeg_quality'])) {
            $upload->setJpegQuality($_CONF['jpeg_quality']);
        }
    }
    $upload->setAllowedMimeTypes(array('image/gif' => '.gif', 'image/jpeg' => '.jpg,.jpeg', 'image/pjpeg' => '.jpg,.jpeg', 'image/x-png' => '.png', 'image/png' => '.png'));
    if (!$upload->setPath($_CONF['path_images'] . 'topics')) {
        $display = COM_showMessageText($upload->printErrors(false), $LANG27[29]);
        $display = COM_createHTMLDocument($display, array('pagetitle' => $LANG27[29]));
        COM_output($display);
        exit;
        // don't return
    }
    $filename = '';
    // see if user wants to upload a (new) icon
    $newIcon = $_FILES['newicon'];
    if (!empty($newIcon['name'])) {
        $pos = strrpos($newIcon['name'], '.') + 1;
        $fExtension = substr($newIcon['name'], $pos);
        $filename = 'topic_' . $tid . '.' . $fExtension;
    }
    // do the upload
    if (!empty($filename)) {
        $upload->setFileNames($filename);
        $upload->setPerms('0644');
        if ($_CONF['max_topicicon_width'] > 0 && $_CONF['max_topicicon_height'] > 0) {
            $upload->setMaxDimensions($_CONF['max_topicicon_width'], $_CONF['max_topicicon_height']);
        } else {
            $upload->setMaxDimensions($_CONF['max_image_width'], $_CONF['max_image_height']);
        }
        if ($_CONF['max_topicicon_size'] > 0) {
            $upload->setMaxFileSize($_CONF['max_topicicon_size']);
        } else {
            $upload->setMaxFileSize($_CONF['max_image_size']);
        }
        $upload->uploadFiles();
        if ($upload->areErrors()) {
            $display = COM_showMessageText($upload->printErrors(false), $LANG27[29]);
            $display = COM_createHTMLDocument($display, array('pagetitle' => $LANG27[29]));
            COM_output($display);
            exit;
            // don't return
        }
        if (strpos($_CONF['path_images'], $_CONF['path_html']) === 0) {
            $filename = substr($_CONF['path_images'], strlen($_CONF['path_html']) - 1) . 'topics/' . $filename;
        } else {
            /**
             * Not really used when the 'path_images' is outside of the webroot.
             * Let's at least extract the name of the images directory then.
             */
            $images = 'images';
            $parts = explode('/', $_CONF['path_images']);
            if (count($parts) > 1) {
                $cnt = count($parts);
                // e.g. from /path/to/myimages/ would extract "myimages"
                if (empty($parts[$cnt - 1]) && !empty($parts[$cnt - 2])) {
                    $images = $parts[$cnt - 2];
                }
                $filename = '/' . $images . '/topics/' . $filename;
            }
        }
    }
    return $filename;
}
开发者ID:mystralkk,项目名称:geeklog,代码行数:89,代码来源:topic.php

示例3: copyFiles

 public function copyFiles($settings, $gid)
 {
     //Допустимые типы
     $validTypes = array('image/jpg', 'image/jpeg', 'image/gif', 'image/wbmp');
     //Поле с которого происходит выбор файлов
     Upload::$index = 'images';
     //Максимальный размер в кб
     Upload::$size = 15000;
     //Передача типов в класс
     Upload::validType($validTypes);
     //Проверка валидности файлов
     $files = Upload::validate();
     //Загрузка во временную директорию
     $result = Upload::uploadFiles($files, 'tmp', true);
     Bufer::add(array('result' => $result));
     $dir_galery_pic = 'uploads/images/galery/' . $gid . '/pic';
     $dir_galery_thumb = 'uploads/images/galery/' . $gid . '/thumb';
     //Если есть файлы, прошедшие проверку
     if (!empty($result['valid'])) {
         foreach ($result['valid'] as $file) {
             $image = $file['hashname'] . '.' . $file['ext'];
             $preview_w = $settings['preview_w'];
             $preview_h = $settings['preview_h'];
             $quality = isset($settings['quality']) ? $settings['quality'] : 100;
             $imageInfo = getimagesize($file['fullpath'], $quality);
             $img = new Images($file['fullpath']);
             $resizeThumb = $img->resize($preview_w, $preview_h, $dir_galery_thumb, $image);
             $width = isset($settings['resize_w']) ? $settings['resize_w'] : $imageInfo[0];
             $height = isset($settings['resize_h']) ? $settings['resize_h'] : $imageInfo[1];
             $img = new Images($file['fullpath']);
             $resizeBig = $img->resize($width, $height, $dir_galery_pic, $image);
             if (isset($settings['watermark_text'])) {
                 $alfa = $settings['water_set']['fontAlpha'];
                 $position = $settings['water_set']['position'];
                 $align = $settings['water_set']['align'];
                 $font = $settings['water_set']['fontFamily'];
                 $size = $settings['water_set']['fontSize'];
                 $color = $settings['water_set']['fontColor'];
                 $margin = $settings['water_set']['margin'];
                 $text = $settings['watermark_text'];
                 $img = new Images($dir_galery_pic . '/' . $image);
                 $img->waterSettings(array('fontAlpha' => $alfa, 'fontSize' => $size, 'fontFamily' => $font, 'fontColor' => $color, 'position' => $position, 'align' => $align, 'margin' => 10));
                 $arrInfo = $img->waterMarkText($text, $dir_galery_pic, false);
             }
             if (isset($settings['watermark_image'])) {
                 $alfa = $settings['water_set']['imgAlpha'];
                 $position = $settings['water_set']['position'];
                 $align = $settings['water_set']['align'];
                 $margin = $settings['water_set']['margin'];
                 $image = $settings['watermark_image'];
                 $img = new Images($dir_galery_pic . '/' . $image);
                 $img->waterSettings(array('imgAlpha' => $alfa, 'position' => $position, 'align' => $align, 'margin' => 10));
                 $arrInfo = $img->waterMarkImg($image, $dir_galery, false);
             }
             $images[] = array('pic' => $dir_galery_pic . '/' . $image, 'thumb' => $dir_galery_thumb . '/' . $image);
             Upload::deleteFile($file['fullpath']);
         }
     }
     if (isset($images) && isset($gid)) {
         $result = $this->addImagesOnDb($gid, $images);
     }
 }
开发者ID:vasinsky,项目名称:fw-test,代码行数:62,代码来源:editgalery.php

示例4: service_submit_story


//.........这里部分代码省略.........
                    $upload->setMogrifyPath($_CONF['path_to_mogrify']);
                } elseif ($_CONF['image_lib'] == 'netpbm') {
                    // using netPBM
                    $upload->setNetPBM($_CONF['path_to_netpbm']);
                } elseif ($_CONF['image_lib'] == 'gdlib') {
                    // using the GD library
                    $upload->setGDLib();
                }
                $upload->setAutomaticResize(true);
                if ($_CONF['keep_unscaled_image'] == 1) {
                    $upload->keepOriginalImage(true);
                } else {
                    $upload->keepOriginalImage(false);
                }
                if (isset($_CONF['jpeg_quality'])) {
                    $upload->setJpegQuality($_CONF['jpeg_quality']);
                }
            }
            $upload->setAllowedMimeTypes(array('image/gif' => '.gif', 'image/jpeg' => '.jpg,.jpeg', 'image/pjpeg' => '.jpg,.jpeg', 'image/x-png' => '.png', 'image/png' => '.png'));
            if (!$upload->setPath($_CONF['path_images'] . 'articles')) {
                $output = COM_showMessageText($upload->printErrors(false), $LANG24[30]);
                $output = COM_createHTMLDocument($output, array('pagetitle' => $LANG24[30]));
                echo $output;
                exit;
            }
            // NOTE: if $_CONF['path_to_mogrify'] is set, the call below will
            // force any images bigger than the passed dimensions to be resized.
            // If mogrify is not set, any images larger than these dimensions
            // will get validation errors
            $upload->setMaxDimensions($_CONF['max_image_width'], $_CONF['max_image_height']);
            $upload->setMaxFileSize($_CONF['max_image_size']);
            // size in bytes, 1048576 = 1MB
            // Set file permissions on file after it gets uploaded (number is in octal)
            $upload->setPerms('0644');
            $filenames = array();
            $end_index = $index_start + $upload->numFiles() - 1;
            for ($z = $index_start; $z <= $end_index; $z++) {
                $curfile = current($_FILES);
                if (!empty($curfile['name'])) {
                    $pos = strrpos($curfile['name'], '.') + 1;
                    $fextension = substr($curfile['name'], $pos);
                    $filenames[] = $sid . '_' . $z . '.' . $fextension;
                }
                next($_FILES);
            }
            $upload->setFileNames($filenames);
            reset($_FILES);
            $upload->uploadFiles();
            if ($upload->areErrors()) {
                $retval = COM_showMessageText($upload->printErrors(false), $LANG24[30]);
                $output = COM_createHTMLDocument($output, array('pagetitle' => $LANG24[30]));
                echo $retval;
                exit;
            }
            reset($filenames);
            for ($z = $index_start; $z <= $end_index; $z++) {
                DB_query("INSERT INTO {$_TABLES['article_images']} (ai_sid, ai_img_num, ai_filename) VALUES ('{$sid}', {$z}, '" . current($filenames) . "')");
                next($filenames);
            }
        }
        if ($_CONF['maximagesperarticle'] > 0) {
            $errors = $story->checkAttachedImages();
            if (count($errors) > 0) {
                $output .= COM_startBlock($LANG24[54], '', COM_getBlockTemplate('_msg_block', 'header'));
                $output .= $LANG24[55] . LB . '<ul>' . LB;
                foreach ($errors as $err) {
                    $output .= '<li>' . $err . '</li>' . LB;
                }
                $output .= '</ul>' . LB;
                $output .= COM_endBlock(COM_getBlockTemplate('_msg_block', 'footer'));
                $output .= storyeditor($sid);
                $output = COM_createHTMLDocument($output, array('pagetitle' => $LANG24[54]));
                echo $output;
                exit;
            }
        }
    }
    $result = $story->saveToDatabase();
    if ($result == STORY_SAVED) {
        // see if any plugins want to act on that story
        if (!empty($args['old_sid']) && $args['old_sid'] != $sid) {
            PLG_itemSaved($sid, 'article', $args['old_sid']);
        } else {
            PLG_itemSaved($sid, 'article');
        }
        // update feed(s)
        COM_rdfUpToDateCheck('article', $story->DisplayElements('tid'), $sid);
        COM_rdfUpToDateCheck('comment');
        STORY_updateLastArticlePublished();
        CMT_updateCommentcodes();
        if ($story->type == 'submission') {
            $output = COM_refresh($_CONF['site_admin_url'] . '/moderation.php?msg=9');
        } else {
            $output = PLG_afterSaveSwitch($_CONF['aftersave_story'], COM_buildURL("{$_CONF['site_url']}/article.php?story={$sid}"), 'story', 9);
        }
        /* @TODO Set the object id here */
        $svc_msg['id'] = $sid;
        return PLG_RET_OK;
    }
}
开发者ID:mystralkk,项目名称:geeklog,代码行数:101,代码来源:lib-story.php

示例5: array

 $PageDataDisplay = $dsiSections->getAllData();
 include 'veiws/editPage.php';
 if (isset($_POST['submit']) && $_POST['submit'] == "Edit") {
     $editPage['page_name'] = $_POST['page_name'];
     $editPage['page_content'] = $_POST['page_content'];
     $editPage['page_status'] = $_POST['page_status'];
     $editPage['sectionId'] = $_POST['sectionId'];
     //$editPage['page_image'] = 'images/logo.png';     // must be reviewed
     if (!empty($_FILES['page_image']['name'][0])) {
         try {
             $file = $_FILES['page_image'];
             $allowedExts = array('jpg', 'png', 'gif', 'jpeg');
             $uploadsDirecotry = "resources/uploads/";
             $maxSize = 4000000;
             $upload = new Upload($file, $allowedExts, $uploadsDirecotry, $maxSize);
             $upload->uploadFiles();
             $editPage['page_image'] = $uploadsDirecotry . $upload->getFileUrl();
         } catch (Exception $exc) {
             $exc->getMessage();
         }
     } else {
         $editPage['page_image'] = 'resources/images/logo.png';
     }
     $tabename = "pages";
     $id = $_GET['id'];
     try {
         $updatePage = new Update($editPage, $tabename);
         $updatedPage = $updatePage->editData($id);
         if ($updatedPage) {
             echo '<script type="text/javascript"> alert("The New Page was updated !"); history.back();</script>';
         }
开发者ID:jeremywong1992,项目名称:awebarts1-93,代码行数:31,代码来源:C_Pages.php

示例6: extractZipFile

 public function extractZipFile()
 {
     $this->file_name = html_entity_decode($this->file_name, ENT_QUOTES);
     $file_path = $this->intDir . DIRECTORY_SEPARATOR . $this->file_name;
     //The zip file name is set in $this->file_name
     $za = new ZipArchiveExtended();
     $za->open($file_path);
     try {
         $za->createTree();
         //get system temporary folder
         $tmpFolder = ini_get('upload_tmp_dir');
         empty($tmpFolder) ? $tmpFolder = "/tmp" : null;
         $tmpFolder .= "/" . uniqid('') . "/";
         mkdir($tmpFolder, 0777, true);
         $fileErrors = $za->extractFilesInTmp($tmpFolder);
         $za->close();
         //compose an array that has the same structure of $_FILES
         $filesArray = array();
         foreach ($za->treeList as $fileName) {
             $filesArray[$fileName] = array('name' => $fileName, 'tmp_name' => $tmpFolder . $fileName, 'error' => null, 'size' => filesize($tmpFolder . $fileName));
         }
         /***
          *
          * ERRORE di un file extratto dallo zip ( isset( $fileErrors[ $fileName ] ) ) ? $fileErrors[ $fileName ] :
          *
          **/
         // The $this->cookieDir parameter makes Upload get the upload directory from the cookie.
         // In this way it'll find the unzipped files
         $uploadFile = new Upload($this->cookieDir);
         $uploadFile->setRaiseException($this->stopOnFileException);
         try {
             $stdResult = $uploadFile->uploadFiles($filesArray);
             if ($this->uploadFailed($stdResult)) {
                 $this->uploadError = true;
                 $this->uploadedFiles = $stdResult;
             }
         } catch (Exception $e) {
             $stdResult = array();
             $this->result = array('errors' => array(array("code" => -1, "message" => $e->getMessage())));
             $this->api_output['message'] = $e->getMessage();
             return null;
         }
         return array_map("Upload::fixFileName", $za->treeList);
     } catch (Exception $e) {
         Log::doLog("ExtendedZipArchive Exception: {$e->getCode()} : {$e->getMessage()}");
         $this->result['errors'][] = array('code' => $e->getCode(), 'message' => "Zip error: " . $e->getMessage(), 'debug' => $this->file_name);
         return null;
     }
     return array();
 }
开发者ID:bcrazvan,项目名称:MateCat,代码行数:50,代码来源:ConversionHandler.php

示例7: _handleImageResize

 protected function _handleImageResize($to_path)
 {
     global $_CONF;
     require_once $_CONF['path_system'] . 'classes/upload.class.php';
     // Figure out file name
     $path_parts = pathinfo($to_path);
     $filename = $path_parts['basename'];
     $upload = new Upload();
     if (!empty($_CONF['image_lib'])) {
         if ($_CONF['image_lib'] == 'imagemagick') {
             // Using imagemagick
             $upload->setMogrifyPath($_CONF['path_to_mogrify']);
         } elseif ($_CONF['image_lib'] == 'netpbm') {
             // using netPBM
             $upload->setNetPBM($_CONF['path_to_netpbm']);
         } elseif ($_CONF['image_lib'] == 'gdlib') {
             // using the GD library
             $upload->setGDLib();
         }
         $upload->setAutomaticResize(true);
         if (isset($_CONF['debug_image_upload']) && $_CONF['debug_image_upload']) {
             $upload->setLogFile($_CONF['path'] . 'logs/error.log');
             $upload->setDebug(true);
         }
         if (isset($_CONF['jpeg_quality'])) {
             $upload->setJpegQuality($_CONF['jpeg_quality']);
         }
     }
     $upload->setAllowedMimeTypes(array('image/gif' => '.gif', 'image/jpeg' => '.jpg,.jpeg', 'image/pjpeg' => '.jpg,.jpeg', 'image/x-png' => '.png', 'image/png' => '.png'));
     // Set new path and image name
     if (!$upload->setPath($_CONF['path_images'] . 'userphotos')) {
         return;
     }
     // Current path of image to resize
     $path = $_CONF['path_images'] . 'userphotos/' . $filename;
     $path_parts = pathinfo($path);
     $_FILES['imagefile']['name'] = $path_parts['basename'];
     $_FILES['imagefile']['tmp_name'] = $path;
     $_FILES['imagefile']['type'] = '';
     switch ($path_parts['extension']) {
         case 'gif':
             $_FILES['imagefile']['type'] = 'image/gif';
             break;
         case 'jpg':
         case 'jpeg':
             $_FILES['imagefile']['type'] = 'image/jpeg';
             break;
         case 'png':
             $_FILES['imagefile']['type'] = 'image/png';
             break;
     }
     $_FILES['imagefile']['size'] = filesize($_FILES['imagefile']['tmp_name']);
     $_FILES['imagefile']['error'] = '';
     $_FILES['imagefile']['non_upload'] = true;
     // Flag to bypass upload process via browser file form
     // do the upload
     if (!empty($filename)) {
         $upload->setFileNames($filename);
         $upload->setPerms('0644');
         if ($_CONF['max_photo_width'] > 0 && $_CONF['max_photo_height'] > 0) {
             $upload->setMaxDimensions($_CONF['max_photo_width'], $_CONF['max_photo_height']);
         } else {
             $upload->setMaxDimensions($_CONF['max_image_width'], $_CONF['max_image_height']);
         }
         if ($_CONF['max_photo_size'] > 0) {
             $upload->setMaxFileSize($_CONF['max_photo_size']);
         } else {
             $upload->setMaxFileSize($_CONF['max_image_size']);
         }
         $upload->uploadFiles();
         if ($upload->areErrors()) {
             return;
         }
     }
     return $path;
     // return new path and filename
 }
开发者ID:Geeklog-Core,项目名称:geeklog,代码行数:77,代码来源:oauthhelper.class.php

示例8: doAction

 public function doAction()
 {
     $uploadFile = new Upload();
     try {
         $stdResult = $uploadFile->uploadFiles($_FILES);
     } catch (Exception $e) {
         $stdResult = array();
         $this->result = array('errors' => array(array("code" => -1, "message" => $e->getMessage())));
         $this->api_output['message'] = $e->getMessage();
     }
     $arFiles = array();
     foreach ($stdResult as $input_name => $input_value) {
         $arFiles[] = $input_value->name;
     }
     //if fileupload was failed this index ( 0 = does not exists )
     $default_project_name = @$arFiles[0];
     if (count($arFiles) > 1) {
         $default_project_name = "MATECAT_PROJ-" . date("Ymdhi");
     }
     if (empty($this->project_name)) {
         $this->project_name = $default_project_name;
         //'NO_NAME'.$this->create_project_name();
     }
     if (empty($this->source_lang)) {
         $this->api_output['message'] = "Missing source language.";
         $this->result['errors'][] = array("code" => -3, "message" => "Missing source language.");
     }
     if (empty($this->target_lang)) {
         $this->api_output['message'] = "Missing target language.";
         $this->result['errors'][] = array("code" => -4, "message" => "Missing target language.");
     }
     //ONE OR MORE ERRORS OCCURRED : EXITING
     //for now we sent to api output only the LAST error message, but we log all
     if (!empty($this->result['errors'])) {
         $msg = "Error \n\n " . var_export(array_merge($this->result, $_POST), true);
         Log::doLog($msg);
         Utils::sendErrMailReport($msg);
         return -1;
         //exit code
     }
     /* Do conversions here */
     $converter = new ConvertFileWrapper($stdResult);
     $converter->intDir = $uploadFile->getUploadPath();
     $converter->errDir = INIT::$CONVERSIONERRORS_REPOSITORY . DIRECTORY_SEPARATOR . $uploadFile->getDirUploadToken();
     $converter->cookieDir = $uploadFile->getDirUploadToken();
     $converter->source_lang = $this->source_lang;
     $converter->target_lang = $this->target_lang;
     $converter->doAction();
     $status = $converter->checkResult();
     if (!empty($status)) {
         $this->api_output['message'] = 'Project Conversion Failure';
         $this->api_output['debug'] = $status;
         $this->result['errors'] = $status;
         Log::doLog($status);
         return -1;
     }
     /* Do conversions here */
     $projectManager = new ProjectManager();
     $projectStructure = $projectManager->getProjectStructure();
     $projectStructure['project_name'] = $this->project_name;
     $projectStructure['result'] = $this->result;
     $projectStructure['private_tm_key'] = $this->private_tm_key;
     $projectStructure['private_tm_user'] = $this->private_tm_user;
     $projectStructure['private_tm_pass'] = $this->private_tm_pass;
     $projectStructure['uploadToken'] = $uploadFile->getDirUploadToken();
     $projectStructure['array_files'] = $arFiles;
     //list of file name
     $projectStructure['source_language'] = $this->source_lang;
     $projectStructure['target_language'] = explode(',', $this->target_lang);
     $projectStructure['mt_engine'] = $this->mt_engine;
     $projectStructure['tms_engine'] = $this->tms_engine;
     $projectStructure['status'] = Constants_ProjectStatus::STATUS_NOT_READY_FOR_ANALYSIS;
     $projectStructure['skip_lang_validation'] = true;
     $projectManager = new ProjectManager($projectStructure);
     $projectManager->createProject();
     $this->result = $projectStructure['result'];
     if (!empty($projectStructure['result']['errors'])) {
         //errors already logged
         $this->api_output['message'] = 'Project Creation Failure';
         $this->api_output['debug'] = $projectStructure['result']['errors'];
     } else {
         //everything ok
         $this->api_output['status'] = 'OK';
         $this->api_output['message'] = 'Success';
         $this->api_output['id_project'] = $projectStructure['result']['id_project'];
         $this->api_output['project_pass'] = $projectStructure['result']['ppassword'];
     }
 }
开发者ID:reysub,项目名称:MateCat,代码行数:88,代码来源:NewController.php

示例9: uploadGlossary

function uploadGlossary($input)
{
    if (in_array($input["source"], $input["targets"])) {
        return array("result" => 0, "message" => "Error: Source lang is equal to one of targets");
    }
    try {
        $uploadFile = new Upload();
        $uploadResult = $uploadFile->uploadFiles($_FILES);
        $input["glossaryURI"] = $uploadResult->glossary->file_path;
    } catch (Exception $e) {
        $errorData = explode("->", $e->getMessage());
        return array("result" => 0, "message" => "Error: " . trim($errorData[1]));
    }
    return array("result" => 1, "message" => "Glossary '" . $input["glossaryName"] . "' successfully uploaded.<br/><br/>");
}
开发者ID:kevinvnloctra,项目名称:MateCat,代码行数:15,代码来源:loadGlossary.php

示例10: doAction

 public function doAction()
 {
     if (!$this->validateAuthHeader()) {
         header('HTTP/1.0 401 Unauthorized');
         $this->api_output['message'] = 'Authentication failed';
         return -1;
     }
     if (@count($this->api_output['debug']) > 0) {
         return;
     }
     $uploadFile = new Upload();
     try {
         $stdResult = $uploadFile->uploadFiles($_FILES);
     } catch (Exception $e) {
         $stdResult = array();
         $this->result = array('errors' => array(array("code" => -1, "message" => $e->getMessage())));
         $this->api_output['message'] = $e->getMessage();
     }
     $arFiles = array();
     foreach ($stdResult as $input_name => $input_value) {
         $arFiles[] = $input_value->name;
     }
     //if fileupload was failed this index ( 0 = does not exists )
     $default_project_name = @$arFiles[0];
     if (count($arFiles) > 1) {
         $default_project_name = "MATECAT_PROJ-" . date("Ymdhi");
     }
     if (empty($this->project_name)) {
         $this->project_name = $default_project_name;
         //'NO_NAME'.$this->create_project_name();
     }
     if (empty($this->source_lang)) {
         $this->api_output['message'] = "Missing source language.";
         $this->result['errors'][] = array("code" => -3, "message" => "Missing source language.");
     }
     if (empty($this->target_lang)) {
         $this->api_output['message'] = "Missing target language.";
         $this->result['errors'][] = array("code" => -4, "message" => "Missing target language.");
     }
     //ONE OR MORE ERRORS OCCURRED : EXITING
     //for now we sent to api output only the LAST error message, but we log all
     if (!empty($this->result['errors'])) {
         $msg = "Error \n\n " . var_export(array_merge($this->result, $_POST), true);
         Log::doLog($msg);
         Utils::sendErrMailReport($msg);
         return -1;
         //exit code
     }
     $cookieDir = $uploadFile->getDirUploadToken();
     $intDir = INIT::$UPLOAD_REPOSITORY . DIRECTORY_SEPARATOR . $cookieDir;
     $errDir = INIT::$STORAGE_DIR . DIRECTORY_SEPARATOR . 'conversion_errors' . DIRECTORY_SEPARATOR . $cookieDir;
     $response_stack = array();
     foreach ($arFiles as $file_name) {
         $ext = FilesStorage::pathinfo_fix($file_name, PATHINFO_EXTENSION);
         $conversionHandler = new ConversionHandler();
         $conversionHandler->setFileName($file_name);
         $conversionHandler->setSourceLang($this->source_lang);
         $conversionHandler->setTargetLang($this->target_lang);
         $conversionHandler->setSegmentationRule($this->seg_rule);
         $conversionHandler->setCookieDir($cookieDir);
         $conversionHandler->setIntDir($intDir);
         $conversionHandler->setErrDir($errDir);
         $status = array();
         if ($ext == "zip") {
             // this makes the conversionhandler accumulate eventual errors on files and continue
             $conversionHandler->setStopOnFileException(false);
             $fileObjects = $conversionHandler->extractZipFile();
             //call convertFileWrapper and start conversions for each file
             if ($conversionHandler->uploadError) {
                 $fileErrors = $conversionHandler->getUploadedFiles();
                 foreach ($fileErrors as $fileError) {
                     if (count($fileError->error) == 0) {
                         continue;
                     }
                     $brokenFileName = ZipArchiveExtended::getFileName($fileError->name);
                     /*
                      * TODO
                      * return error code is 2 because
                      *      <=0 is for errors
                      *      1   is OK
                      *
                      * In this case, we raise warnings, hence the return code must be a new code
                      */
                     $this->result['code'] = 2;
                     $this->result['errors'][$brokenFileName] = array('code' => $fileError->error['code'], 'message' => $fileError->error['message'], 'debug' => $brokenFileName);
                 }
             }
             $realFileObjectInfo = $fileObjects;
             $realFileObjectNames = array_map(array('ZipArchiveExtended', 'getFileName'), $fileObjects);
             foreach ($realFileObjectNames as $i => &$fileObject) {
                 $__fileName = $fileObject;
                 $__realFileName = $realFileObjectInfo[$i];
                 $filesize = filesize($intDir . DIRECTORY_SEPARATOR . $__realFileName);
                 $fileObject = array('name' => $__fileName, 'size' => $filesize);
                 $realFileObjectInfo[$i] = $fileObject;
             }
             $this->result['data'][$file_name] = json_encode($realFileObjectNames);
             $stdFileObjects = array();
             if ($fileObjects !== null) {
                 foreach ($fileObjects as $fName) {
//.........这里部分代码省略.........
开发者ID:bcrazvan,项目名称:MateCat,代码行数:101,代码来源:NewController.php

示例11: handlePhotoUpload

/**
 * Upload new photo, delete old photo
 *
 * @param    string $delete_photo 'on': delete old photo
 * @return   string                  filename of new photo (empty = no new photo)
 */
function handlePhotoUpload($delete_photo = '')
{
    global $_CONF, $_TABLES, $_USER, $LANG24;
    require_once $_CONF['path_system'] . 'classes/upload.class.php';
    $upload = new Upload();
    if (!empty($_CONF['image_lib'])) {
        if ($_CONF['image_lib'] === 'imagemagick') {
            // Using imagemagick
            $upload->setMogrifyPath($_CONF['path_to_mogrify']);
        } elseif ($_CONF['image_lib'] === 'netpbm') {
            // using netPBM
            $upload->setNetPBM($_CONF['path_to_netpbm']);
        } elseif ($_CONF['image_lib'] === 'gdlib') {
            // using the GD library
            $upload->setGDLib();
        }
        $upload->setAutomaticResize(true);
        if (isset($_CONF['debug_image_upload']) && $_CONF['debug_image_upload']) {
            $upload->setLogFile($_CONF['path'] . 'logs/error.log');
            $upload->setDebug(true);
        }
        if (isset($_CONF['jpeg_quality'])) {
            $upload->setJpegQuality($_CONF['jpeg_quality']);
        }
    }
    $upload->setAllowedMimeTypes(array('image/gif' => '.gif', 'image/jpeg' => '.jpg,.jpeg', 'image/pjpeg' => '.jpg,.jpeg', 'image/x-png' => '.png', 'image/png' => '.png'));
    if (!$upload->setPath($_CONF['path_images'] . 'userphotos')) {
        $display = COM_showMessageText($upload->printErrors(false), $LANG24[30]) . COM_createHTMLDocument($display, array('pagetitle' => $LANG24[30]));
        COM_output($display);
        exit;
        // don't return
    }
    $filename = '';
    if (!empty($delete_photo) && $delete_photo === 'on') {
        $delete_photo = true;
    } else {
        $delete_photo = false;
    }
    $curphoto = DB_getItem($_TABLES['users'], 'photo', "uid = {$_USER['uid']}");
    if (empty($curphoto)) {
        $delete_photo = false;
    }
    // see if user wants to upload a (new) photo
    $newphoto = $_FILES['photo'];
    if (!empty($newphoto['name'])) {
        $pos = strrpos($newphoto['name'], '.') + 1;
        $fextension = substr($newphoto['name'], $pos);
        $filename = $_USER['username'] . '.' . $fextension;
        if (!empty($curphoto) && $filename != $curphoto) {
            $delete_photo = true;
        } else {
            $delete_photo = false;
        }
    }
    // delete old photo first
    if ($delete_photo) {
        USER_deletePhoto($curphoto);
    }
    // now do the upload
    if (!empty($filename)) {
        $upload->setFileNames($filename);
        $upload->setPerms('0644');
        if ($_CONF['max_photo_width'] > 0 && $_CONF['max_photo_height'] > 0) {
            $upload->setMaxDimensions($_CONF['max_photo_width'], $_CONF['max_photo_height']);
        } else {
            $upload->setMaxDimensions($_CONF['max_image_width'], $_CONF['max_image_height']);
        }
        if ($_CONF['max_photo_size'] > 0) {
            $upload->setMaxFileSize($_CONF['max_photo_size']);
        } else {
            $upload->setMaxFileSize($_CONF['max_image_size']);
        }
        $upload->uploadFiles();
        if ($upload->areErrors()) {
            $display = COM_showMessageText($upload->printErrors(false), $LANG24[30]);
            $display = COM_createHTMLDocument($display, array('pagetitle' => $LANG24[30]));
            COM_output($display);
            exit;
            // don't return
        }
    } elseif (!$delete_photo && !empty($curphoto)) {
        $filename = $curphoto;
    }
    return $filename;
}
开发者ID:Geeklog-Core,项目名称:geeklog,代码行数:91,代码来源:usersettings.php

示例12: importusers

/**
* This function allows the administrator to import batches of users
*
* TODO: This function should first display the users that are to be imported,
* together with the invalid users and the reason of invalidity. Each valid line
* should have a checkbox that allows selection of final to be imported users.
* After clicking an extra button, the actual import should take place. This will
* prevent problems in case the list formatting is incorrect.
*
* @return   string          HTML with success or error message
*
*/
function importusers()
{
    global $_CONF, $_TABLES, $LANG04, $LANG28;
    // Setting this to true will cause import to print processing status to
    // webpage and to the error.log file
    $verbose_import = true;
    $retval = '';
    // Bulk import implies admin authorisation:
    $_CONF['usersubmission'] = 0;
    // First, upload the file
    require_once $_CONF['path_system'] . 'classes/upload.class.php';
    $upload = new Upload();
    $upload->setPath($_CONF['path_data']);
    $upload->setAllowedMimeTypes(array('text/plain' => '.txt'));
    $upload->setFileNames('user_import_file.txt');
    if ($upload->uploadFiles()) {
        // Good, file got uploaded, now install everything
        $thefile = current($_FILES);
        $filename = $_CONF['path_data'] . 'user_import_file.txt';
        if (!file_exists($filename)) {
            // empty upload form
            COM_redirect($_CONF['site_admin_url'] . '/user.php?mode=importform');
        }
    } else {
        // A problem occurred, print debug information
        $retval = COM_showMessageText($upload->printErrors(false), $LANG28[24]);
        $retval = COM_createHTMLDocument($retval, array('pagetitle' => $LANG28[22]));
        return $retval;
    }
    $users = file($filename);
    $retval .= COM_startBlock($LANG28[31], '', COM_getBlockTemplate('_admin_block', 'header'));
    // Following variables track import processing statistics
    $successes = 0;
    $failures = 0;
    foreach ($users as $line) {
        $line = rtrim($line);
        if (empty($line)) {
            continue;
        }
        list($full_name, $u_name, $email) = explode("\t", $line);
        $full_name = strip_tags($full_name);
        $u_name = COM_applyFilter($u_name);
        $email = COM_applyFilter($email);
        if ($verbose_import) {
            $retval .= "<br" . XHTML . "><b>Working on username={$u_name}, fullname={$full_name}, and email={$email}</b><br" . XHTML . ">\n";
            COM_errorLog("Working on username={$u_name}, fullname={$full_name}, and email={$email}", 1);
        }
        // prepare for database
        $userName = trim($u_name);
        $fullName = trim($full_name);
        $emailAddr = trim($email);
        if (COM_isEmail($email)) {
            // email is valid form
            $ucount = DB_count($_TABLES['users'], 'username', DB_escapeString($userName));
            $ecount = DB_count($_TABLES['users'], 'email', DB_escapeString($emailAddr));
            if ($ucount == 0 && $ecount == 0) {
                // user doesn't already exist - pass in optional true for $batchimport parm
                $uid = USER_createAccount($userName, $emailAddr, '', $fullName, '', '', '', true);
                $result = USER_createAndSendPassword($userName, $emailAddr, $uid);
                if ($result) {
                    $successes++;
                    if ($verbose_import) {
                        $retval .= "<br" . XHTML . "> Account for <b>{$u_name}</b> created successfully.<br" . XHTML . ">\n";
                        COM_errorLog("Account for {$u_name} created successfully", 1);
                    }
                } else {
                    // user creation failed
                    $retval .= "<br" . XHTML . ">ERROR: There was a problem creating the account for <b>{$u_name}</b>.<br" . XHTML . ">\n";
                    COM_errorLog("ERROR: here was a problem creating the account for {$u_name}.", 1);
                }
            } else {
                if ($verbose_import) {
                    $retval .= "<br" . XHTML . "><b>{$u_name}</b> or <b>{$email}</b> already exists, account not created.<br" . XHTML . ">\n";
                    // user already exists
                    COM_errorLog("{$u_name},{$email}: username or email already exists, account not created", 1);
                }
                $failures++;
            }
            // end if $ucount == 0 && ecount == 0
        } else {
            if ($verbose_import) {
                $retval .= "<br" . XHTML . "><b>{$email}</b> is not a valid email address, account not created<br" . XHTML . ">\n";
                // malformed email
                COM_errorLog("{$email} is not a valid email address, account not created", 1);
            }
            $failures++;
        }
        // end if COM_isEmail($email)
//.........这里部分代码省略.........
开发者ID:Geeklog-Core,项目名称:geeklog,代码行数:101,代码来源:user.php


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