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


PHP DataHandler::createFolderIfNotExist方法代码示例

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


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

示例1: getZipedFiles

 /**
  * envie por post uma array de ids de files, só os ids
  * file/get_ziped_files
  */
 public function getZipedFiles()
 {
     if (!UserClient::getId() > 0) {
         //nao tem permissao
         Navigation::redirect("405");
         exit;
     }
     $array_file_ids = DataHandler::getValueByArrayIndex($_POST, "file_id");
     //Debug::print_r($_REQUEST);
     $array_file_vo = array();
     if (is_array($array_file_ids)) {
         foreach ($array_file_ids as $id) {
             $FileVO = new FileVO();
             $Result = $FileVO->setId($id, TRUE);
             if ($Result->success == TRUE) {
                 $array_file_vo[] = $FileVO;
             }
         }
     } else {
         //erro, não é uma array, verifica se pelo menos é 1 único id
         $id = DataHandler::forceInt($array_file_ids);
         if ($id > 0) {
             //é um id único
             $FileVO = new FileVO();
             $Result = $FileVO->setId($id, TRUE);
             if ($Result->success == TRUE) {
                 $array_file_vo[] = $FileVO;
             }
         } else {
             //erro mesmo, esse dado é zoado, estoura excessão
             throw new Exception("No ids sended", 404);
             exit;
         }
     }
     //a pasta zip precisa existir
     DataHandler::createFolderIfNotExist("upload/zip/");
     //verifica o nome do arquivo baseado nos ids enviados conforme regra inventada agora
     $zip_name = "upload/zip/" . md5(implode("|", $array_file_ids));
     DataHandler::createFolderIfNotExist($zip_name);
     $zip_name = $zip_name . "/teto.zip";
     if (!file_exists($zip_name)) {
         //echo Debug::li($zip_name);exit();
         $Zip = new ZipArchive();
         $Zip->open($zip_name, ZipArchive::CREATE);
         foreach ($array_file_vo as $FileVO) {
             $url = $FileVO->getUrl();
             $array = explode("/", $url);
             $file = $array[count($array) - 1];
             $Zip->addFile($url, $file);
         }
         $Zip->close();
     }
     header("Location: " . Config::getRootPath($zip_name));
     exit;
 }
开发者ID:reytuty,项目名称:facil,代码行数:59,代码来源:File.php

示例2: insert

 public function insert()
 {
     //inicia um retorno de ReturnResultVO
     $ReturnResultVO = new ReturnResultVO();
     //pega os dados baseado na infoPost
     $VO = new FileVO();
     if ($this->infoPost->file_info_id) {
         $VO->setId($this->infoPost->file_info_id, TRUE);
     }
     $VO->setActive($this->infoPost->file_info_active);
     $VO->setName($this->infoPost->file_info_name);
     $VO->setDescription($this->infoPost->file_info_description);
     $VO->setType($this->infoPost->file_info_type);
     $VO->setAuthor($this->infoPost->file_info_author);
     $VO->setLocale($this->infoPost->file_info_locale);
     $VO->setOrder($this->infoPost->file_info_order);
     //("JÁ") gera id para criar pasta onde vai ser guardado o arquivo
     $ReturnResultFileVO = $VO->commit();
     if ($ReturnResultFileVO->success) {
         $ReturnResultFileVO->result = $VO->getId();
     } else {
         //erro, os motivos estão na ReturnResultVO abaixo
         return $ReturnResultFileVO;
     }
     //pega o id da file
     $FILE_ID = $VO->getId();
     $ReturnResultFileVO = new ReturnResultVO();
     if (isset($this->infoPost->file_data) && !$this->infoPost->file_info_id > 0) {
         set_time_limit(0);
         $sentFileData = $this->infoPost->file_data;
         //$_FILES['Filedata'];
         $name = $sentFileData['name'];
         // extens�o enviada
         $sentExtension = DataHandler::returnExtensionOfFile($name);
         // remove caracteres escrotos
         $name = DataHandler::returnFilenameWithoutExtension($name);
         $name = DataHandler::removeAccent($name);
         $name = DataHandler::removeSpecialCharacters($name);
         $name = trim(substr($name, 0, 80));
         switch ($sentFileData["type"]) {
             case "text/plain":
                 $extension = "txt";
                 break;
             default:
                 $extension = strtolower($sentExtension);
                 break;
         }
         //verifica se a pasta existe, se não existir, inventa
         DataHandler::createFolderIfNotExist($this->defaultFolderForNewFiles);
         // pasta de upload de files está no config.php
         $tempFolder = DataHandler::removeDobleBars($this->defaultFolderForNewFiles . "/" . $FILE_ID);
         DataHandler::createFolderIfNotExist($tempFolder);
         $tempUrl = $tempFolder . "/" . strtolower($name . "." . $extension);
         $i = 2;
         while (file_exists($tempUrl)) {
             $tempUrl = $tempFolder . "/" . strtolower($name . "-" . $i . "." . $extension);
             $i++;
         }
         $VO->setUrl($tempUrl);
         $ReturnResultFileVO = $VO->commit();
         //Debug::li("aaa");
         if ($ReturnResultFileVO->success) {
             //incluir o vinculo com a linked_table e linked_table_id
             //receber 	table
             //			table_id
             if ($this->infoPost->table) {
                 $table = $this->infoPost->table;
                 $table_id = $this->infoPost->table_id;
                 include_once "library/facil3/core/dao/LinkDAO.class.php";
                 $LinkDAO = new LinkDAO();
                 //vincula a foto ao table e table_id enviado
                 $ReturnResultVinculoVO = $LinkDAO->insert($table, $table_id, $this->moduleName, $VO->getId(), 1);
                 if (!$ReturnResultVinculoVO->success) {
                     //deu erro ao vincular
                     $ReturnResultVO->success = false;
                     $ReturnResultVO->appendMessage($ReturnResultVinculoVO->array_messages);
                     return $ReturnResultVO;
                 }
             } else {
                 $ReturnResultVO->addMessage(Translation::text("LibraryLanguage::WARNING_FILE_NO_LINKED_TABLE"));
             }
             //movendo o arquivo para sua respectiva pasta.
             $localFile = $VO->getUrl();
             if (!move_uploaded_file($sentFileData['tmp_name'], $localFile)) {
                 $ReturnResultVO->success = false;
                 $ReturnResultVO->addMessage(Translation::text("Arquivo não encontrado"));
                 return $ReturnResultVO;
             } else {
                 $ReturnResultVO->success = TRUE;
                 $ReturnResultVO->result = $VO->getId();
                 $ReturnResultVO->addMessage(Translation::text("Arquivo gravado"));
             }
         } else {
             return $ReturnResultFileVO;
         }
         return $ReturnResultVO;
     } else {
         $ReturnResultFileVO = new ReturnResultVO();
         $ReturnResultFileVO->addMessage("Envie o Filedata");
         // nao veio filedata
//.........这里部分代码省略.........
开发者ID:reytuty,项目名称:facil,代码行数:101,代码来源:FacilFile.php

示例3: getZip

 /**
  * baixar o zip do mal
  * ?products={product_id:N,gallery:true,dimensions:true,files:[]}|{product_id:N,gallery:true,dimensions:true,files:[]}
  */
 public function getZip()
 {
     if (!UserClient::getId() > 0) {
         //nao tem permissao
         Navigation::redirect("405");
         exit;
     }
     set_time_limit(0);
     //tratando variaveis enviadas
     $files_id = DataHandler::getValueByArrayIndex($_POST, "file_id");
     $imagens = DataHandler::getValueByArrayIndex($_POST, "imagens");
     $pdf = DataHandler::getValueByArrayIndex($_POST, "pdf");
     //precisa saber quais sao os produtos envolvidos
     $array_products_id = array();
     $array_files = array();
     if ($files_id) {
         foreach ($files_id as $file_id) {
             $temp_array = explode("_", $file_id);
             $product_id = $temp_array[0];
             if (!in_array($product_id, $array_products_id)) {
                 $array_products_id[] = $product_id;
                 $array_files[] = $product_id;
             }
         }
     }
     if ($imagens) {
         foreach ($imagens as $product_id) {
             if (!in_array($product_id, $array_products_id)) {
                 $array_products_id[] = $product_id;
             }
         }
     }
     if ($pdf) {
         foreach ($pdf as $product_id) {
             if (!in_array($product_id, $array_products_id)) {
                 $array_products_id[] = $product_id;
             }
         }
     }
     $ReturnResultVO = new ReturnResultVO();
     $ProductVO = new ContentSiteVO();
     $FileVO = new FileVO();
     //se tiver produtos para tratar
     if (count($array_products_id) > 0) {
         //a pasta zip precisa existir
         $zip_path = "upload/zip/";
         DataHandler::createFolderIfNotExist($zip_path);
         $array_products_to_zip = array();
         $unique_str = "";
         //nome final do zip que vai baixar, adiciona alguns parametros indicadores
         $zip_name = "teto";
         if (count($array_products_id) > 0) {
             //sao varios produtos
             $zip_name = $zip_name . "_produtos";
         }
         //cada indice dessa array, tem que ser array, terá um json com as info:
         foreach ($array_products_id as $product_id) {
             $resultProduto = $ProductVO->setId($product_id, TRUE);
             if ($resultProduto->success) {
                 $stdProduct = $ProductVO->toStdClass();
                 $array_products_to_zip[] = $stdProduct;
                 $array_images = array();
                 if ($imagens) {
                     if (in_array($product_id, $imagens)) {
                         $array_gallery = $ProductVO->getImages(NULL, "gallery", true);
                         foreach ($array_gallery as $imageVO) {
                             $array_images[] = $imageVO->getURL();
                             $unique_str .= "|" . $imageVO->getId();
                             //add a imagem na pasta
                         }
                         //
                         $array_dimensions = $ProductVO->getImages(NULL, "dimensions", true);
                         foreach ($array_dimensions as $imageVO) {
                             $array_images[] = $imageVO->getURL();
                             //add a imagem na pasta
                             $unique_str .= "|" . $imageVO->getId();
                         }
                     }
                 }
                 $stdProduct->images = $array_images;
                 $array_file_vo = array();
                 //cria a pasta do produto no zip
                 $product_folder_name = DataHandler::strToURL($stdProduct->title);
                 if (count($array_files) > 0) {
                     if (in_array($product_id, $array_files)) {
                         //esse produto pediu algum file
                         $temp_array_files = $ProductVO->getFiles();
                         foreach ($temp_array_files as $FileVO) {
                             if (in_array($FileVO->id, $files_id)) {
                                 $array_file_vo[] = $FileVO;
                                 $unique_str .= "|f." . $file_id;
                                 //add a url do arquivo no zip na pasta
                             }
                         }
                     }
                 }
//.........这里部分代码省略.........
开发者ID:reytuty,项目名称:facil,代码行数:101,代码来源:Produtos.php

示例4: insert

 /**
  * recebe a imagem por post
  * @return ReturnResultVO
  */
 public function insert()
 {
     //inicia um retorno de ReturnResultVO
     $ReturnResultVO = new ReturnResultVO();
     //pega os dados baseado na infoPost
     $VO = new ImageVO();
     //var_dump($this->infoPost);
     //exit();
     if ($this->infoPost->image_info_id > 0) {
         //passou o id, vai atualizar essa VO
         //					echo Debug::li("image_info_id >>>>>>>>>> ".$this->infoPost->image_info_id);
         $VO->setId($this->infoPost->image_info_id, TRUE);
     }
     $VO->setActive($this->infoPost->image_info_active);
     $VO->setName($this->infoPost->image_info_name);
     $VO->setDescription($this->infoPost->image_info_description);
     $VO->setType($this->infoPost->image_info_type);
     $VO->setAuthor($this->infoPost->image_info_author);
     $VO->setLocale($this->infoPost->image_info_locale);
     $VO->setOrder($this->infoPost->image_info_order);
     //				var_dump($_FILES);
     //				var_dump($this->infoPost->file_data);
     //comitando as infos enviadas, dados apenas
     if ($VO->getId() > 0 || $this->infoPost->file_data['tmp_name']) {
         //só comita a imagem se tiver ou id ou enviado o file_data, se não nem tem o que fazer
         $ReturnResultImageVO = $VO->commit();
     } else {
         //nem enviou o id e nem o file_data, retorna
         $ReturnResultVO->addMessage(Translation::text("Have nothing to commit."));
         return $ReturnResultVO;
     }
     if ($ReturnResultImageVO->success) {
         $ReturnResultImageVO->result = $VO->getId();
     } else {
         //erro, os motivos estão na ReturnResultVO abaixo
         return $ReturnResultImageVO;
     }
     //pega o id da imagem
     $IMAGE_ID = $VO->getId();
     $ReturnResultImageVO = new ReturnResultVO();
     //echo Debug::li("this->infoPost->file_data: ".$this->infoPost->file_data);
     if (isset($this->infoPost->file_data) && $this->infoPost->file_data['tmp_name']) {
         set_time_limit(0);
         //var_dump($_FILES);
         $sentFileData = $this->infoPost->file_data;
         //$_FILES['Filedata'];
         $name = $sentFileData['name'];
         // extens�o enviada
         $sentExtension = DataHandler::returnExtensionOfFile($name);
         // remove caracteres escrotos
         $name = DataHandler::returnFilenameWithoutExtension($name);
         $name = DataHandler::removeAccent($name);
         $name = DataHandler::removeSpecialCharacters($name);
         $name = trim(substr($name, 0, 80));
         switch ($sentFileData["type"]) {
             case "image/pjpeg":
             case "image/jpeg":
             case "image/jpg":
                 $extension = "jpg";
                 break;
             case "image/gif":
                 $extension = "gif";
                 break;
             case "image/png":
             case "image/x-png":
                 $extension = "png";
                 break;
             case "image/bmp":
                 $extension = "bmp";
                 break;
             default:
                 $extension = strtolower($sentExtension);
                 break;
         }
         //verifica se a pasta existe, se não existir, inventa
         DataHandler::createFolderIfNotExist($this->defaultFolderForNewImages);
         // pasta de upload de imagens est� no config.php
         $tempFolder = DataHandler::removeDobleBars($this->defaultFolderForNewImages . "/" . $IMAGE_ID);
         DataHandler::createFolderIfNotExist($tempFolder);
         //echo Debug::li("name: $name");
         $tempUrl = $tempFolder . "/original_" . strtolower($name . "." . $extension);
         //echo Debug::li("tempUrl: $tempUrl");
         //exit();
         $i = 2;
         while (file_exists($tempUrl)) {
             $tempUrl = $tempFolder . "/original_" . strtolower($name . "-" . $i . "." . $extension);
             $i++;
         }
         $VO->setUrl($tempUrl);
         $ReturnResultImageVO = $VO->commit();
         //Debug::li("aaa");
         //Debug::print_r($ReturnResultImageVO);
         if ($ReturnResultImageVO->success) {
             //incluir o vinculo com a linked_table e linked_table_id
             //receber 	table
             //			table_id
//.........这里部分代码省略.........
开发者ID:reytuty,项目名称:facil,代码行数:101,代码来源:FacilImage.php


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