Ejemplo n.º 1
0
 /**
  * Function _fnUploadFile to upload file.Uploads muliple format files such as image,text,document,pdf,video,audio.
  * @param string $strOldFileName
  * @param string $strUpFileName
  * @param string $strFolderName
  * @param string $intHeightVal
  * @param string $intWidthVal
  * @param string $strFileTypes
  * @param int $height
  * @param int $width
  * @param string $strSmallImgNewFileName
  * @return mixed
  */
 function _fnUploadFile($strOldFileName, $strUpFileName, $strFolderName, $intHeightVal = 0, $intWidthVal = 0, $strFileTypes = "img", $height = 0, $width = 0, $strSmallImgNewFileName = "")
 {
     /*ECHO " $strOldFileName ==><BR> $strUpFileName ==><BR>$strFolderName ==><BR>$intHeightVal ==><BR>,$intWidthVal==> <BR> $strFileTypes ==><BR> $height==><BR> $width ==> $strSmallImgNewFileName ";EXIT;*/
     global $strImgFileNewNameTemp, $strSource, $strDest;
     ### SOLID FILE UPLOADING CODE ###
     #-- if file uploaded --#
     if ($strFileTypes == "img") {
         $arrAllowImageTypes = array("jpg", "jpeg", "gif", "png");
         //$arrAllowImageTypes = array("jpg");
         //$strFileTypes = "\"jpg\",\"jpeg\",\"gif\",\"png\"";
     } elseif ($strFileTypes == "doc") {
         $arrAllowImageTypes = array("doc", "pdf", "rtf", "txt", "xls", "html", "html", "ppt", "csv", "docx", "xlsx");
         //$strFileTypes = "\"doc\",\"pdf\",\"rtf\",\"txt\"";
     } elseif ($strFileTypes == "video") {
         $arrAllowImageTypes = array("mp4", "wmv", "mov", "mpg", "avi", "flv");
         //$arrAllowImageTypes = array("flv");
     } elseif ($strFileTypes == "podcast") {
         $arrAllowImageTypes = array("mov", "mp3", "mpe", "mp4", "mpeg");
     } elseif ($strFileTypes == "csv") {
         $arrAllowImageTypes = array("csv", "xls", "xlsx");
     } elseif ($strFileTypes == "resume") {
         $arrAllowImageTypes = array("doc", "pdf", "rtf", "txt", "docx");
     }
     $strImgFileSize = (int) $_FILES[$strOldFileName]["size"];
     if ($strImgFileSize) {
         if ($strFileTypes == "video" && $strImgFileSize > 52428800) {
             $strError .= "<p>Please upload video up to 50 MB.</p>";
         } elseif ($strFileTypes == "img" && $strImgFileSize > 4194304) {
             $strErrorMessage .= "<p>Please upload image  up to 4 MB.</p>";
         } else {
             $strFileSuccess = 1;
             $strImgFileName = $_FILES[$strOldFileName]["name"];
             $strImgFileError = (int) $_FILES[$strOldFileName]["error"];
             if ($strImgFileError) {
                 $strErrorMessage .= "<b>{$strImgFileName}</b> Error in uploaded File<br>";
                 $strFileSuccess = 0;
             }
             if ((int) $strFileSuccess) {
                 $strImgFileName = $_FILES[$strOldFileName]["name"];
                 $strImgFileTmpName = $_FILES[$strOldFileName]["tmp_name"];
                 #-- get the file extention
                 $arrImgFileExtention = array_reverse(explode(".", $strImgFileName));
                 $strImgFileExtention = strtolower($arrImgFileExtention[0]);
                 #-- create new unique filename to avoide file overwriting situation --#
                 $strImgFileNewNameTemp = $strUpFileName . "_" . time();
                 $strImgFileNewName = $strImgFileNewNameTemp . "." . $strImgFileExtention;
                 if (!in_array($strImgFileExtention, $arrAllowImageTypes)) {
                     $strErrorMessage .= "<b>{$strImgFileExtention}</b> File Type not allowed for {$strImgFileName}<br>";
                     $strFileSuccess = 0;
                     return "error=" . $strErrorMessage;
                 }
                 if ((int) $strFileSuccess) {
                     #-- move file to server --#
                     if ($strFileTypes == "img") {
                         $arrHeightWidth = array();
                         // $arrHeightWidth = clsUtil::fnSetImageHeighWidth($strImgFileTmpName, $height, $width);
                         if ($strSmallImgNewFileName != "") {
                             if ($height == 0 && $width == 0) {
                                 if (!move_uploaded_file($strImgFileTmpName, DOCUMENT_ROOT . "/usercontent/" . $strFolderName . "/" . $strSmallImgNewFileName)) {
                                     $strErrorMessage .= "<b>{$strImgFileName}</b> File Could not upload<br>";
                                 }
                             } else {
                                 if (ISLOCAL == 0) {
                                     clsUtil::image_resize($strImgFileTmpName, DOCUMENT_ROOT . "/usercontent/" . $strFolderName . "/" . $strSmallImgNewFileName, $height, $width);
                                 } else {
                                     clsUtil::image_resize_local($strImgFileTmpName, DOCUMENT_ROOT . "/usercontent/" . $strFolderName . "/" . $strSmallImgNewFileName, $height, $width);
                                 }
                             }
                         } else {
                             if ($height == 0 && $width == 0) {
                                 if (!move_uploaded_file($strImgFileTmpName, DOCUMENT_ROOT . "/usercontent/" . $strFolderName . "/" . $strImgFileNewName)) {
                                     $strErrorMessage .= "<b>{$strImgFileName}</b> File Could not upload<br>";
                                 }
                             } else {
                                 if (ISLOCAL == 0) {
                                     clsUtil::image_resize($strImgFileTmpName, DOCUMENT_ROOT . "/usercontent/" . $strFolderName . "/" . $strImgFileNewName, $height, $width);
                                 } else {
                                     clsUtil::image_resize_local($strImgFileTmpName, DOCUMENT_ROOT . "/usercontent/" . $strFolderName . "/" . $strImgFileNewName, $height, $width);
                                 }
                             }
                         }
                     } else {
                         if (!move_uploaded_file($strImgFileTmpName, DOCUMENT_ROOT . "/usercontent/" . $strFolderName . "/" . $strImgFileNewName)) {
                             $strErrorMessage .= "<b>{$strImgFileName}</b> File Could not upload<br>";
                         } else {
                             if ($strFileTypes == "video") {
                                 if ($strImgFileExtention != "flv") {
                                     $strSource = DOCUMENT_ROOT . "/usercontent/" . $strFolderName . "/" . $strImgFileNewName;
                                     $strDestinationFLV = DOCUMENT_ROOT . "/usercontent/" . $strFolderName . "/" . $strImgFileNewNameTemp . ".flv";
                                     $output = clsUtil::runExternal("/usr/bin/ffmpeg -i {$strSource} -ar 22050 -ab 32 -f flv -s 320„240 {$strDestinationFLV}", $code);
                                     $strImgFileNewName = $strImgFileNewNameTemp . ".flv";
                                     @unlink($strSource);
                                     if ($code) {
                                         $strErrorMessage .= "<p>Please check the file type.</p>";
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     } else {
         $strErrorMessage .= "<p>Please check the size.</p>";
     }
     if ($strErrorMessage == "") {
         //------------insert record into log table Changes By Onkar for server migration on 26/03/09------//
         $strImageLocationForLog = "usercontent/" . $strFolderName . "/" . $strImgFileNewName;
         return "success=" . $strImgFileNewName;
     } else {
         return "error=" . $strErrorMessage;
     }
 }