Esempio n. 1
0
 function changeIcon($key)
 {
     $to_dir = PATHTOICONDIR . "/";
     $file_name = $key . findExtension($key);
     $this->saveFile($_FILES[$key]["tmp_name"], $to_dir, $file_name);
     $this->updateData("file", $file_name, $key);
 }
 function createAction()
 {
     $this->_helper->layout->disableLayout();
     $this->_helper->viewRenderer->setNoRender(TRUE);
     $session = SessionWrapper::getInstance();
     $this->_translate = Zend_Registry::get("translate");
     $config = Zend_Registry::get("config");
     $formvalues = $this->_getAllParams();
     // debugMessage($formvalues); exit();
     $isuserdoc = false;
     $iscompanydoc = false;
     if (!isArrayKeyAnEmptyString('userid', $formvalues)) {
         $isuserdoc = true;
         $folderid = $formvalues['userid'];
     } else {
         $iscompanydoc = true;
         $folderid = getCompanyID();
     }
     if (isset($_FILES["FileInput"]) && $_FILES["FileInput"]["error"] == UPLOAD_ERR_OK && !array_key_exists('submit', $formvalues)) {
         if (!isset($_FILES['FileInput']['name'])) {
             $error = "<span class='alert alert-danger blocked'>Error: Please select a File to Upload.</span>";
             $result = array('msg' => $error, 'result' => '');
             echo $error;
             exit;
         }
         // if uploading a user document
         if ($isuserdoc) {
             // base path for user documents
             $destination_path = BASE_PATH . DIRECTORY_SEPARATOR . "uploads" . DIRECTORY_SEPARATOR . "users" . DIRECTORY_SEPARATOR . "user_";
             // determine if user has destination avatar folder. Else user is editing there picture
             if (!is_dir($destination_path . $folderid)) {
                 // no folder exits. Create the folder
                 mkdir($destination_path . $folderid, 0775);
             }
         }
         // if uploading a company document
         if ($iscompanydoc) {
             // base path for user documents
             $destination_path = BASE_PATH . DIRECTORY_SEPARATOR . "uploads" . DIRECTORY_SEPARATOR . "company" . DIRECTORY_SEPARATOR . "comp_";
             // determine if user has destination avatar folder. Else user is editing there picture
             if (!is_dir($destination_path . $folderid)) {
                 // no folder exits. Create the folder
                 mkdir($destination_path . $folderid, 0775);
             }
         }
         $destination_path = $destination_path . $folderid . DIRECTORY_SEPARATOR . "documents";
         if (!is_dir($destination_path)) {
             mkdir($destination_path, 0775);
         }
         // create archive folder for each user
         $archivefolder = $destination_path . DIRECTORY_SEPARATOR . "archive";
         if (!is_dir($archivefolder)) {
             mkdir($archivefolder, 0775);
         }
         $oldfile = $_FILES['FileInput']['name'];
         $File_Name = strtolower($oldfile);
         $File_Ext = findExtension($File_Name);
         //get file extention
         $ext = strtolower($_FILES['FileInput']['type']);
         // debugMessage($ext);
         $allowedformatsarray = explode(',', str_replace(' ', '', $config->uploads->docallowedformats));
         // debugMessage($allowedformatsarray);exit();
         $uploadedext = findExtension($File_Name);
         $currenttime = time();
         //Random number to be added to name.
         $currenttime_file = $currenttime . '.' . $uploadedext;
         $thefilename = $destination_path . DIRECTORY_SEPARATOR . $currenttime_file;
         if (isEmptyString($folderid)) {
             $destination_path = BASE_PATH . DIRECTORY_SEPARATOR . "uploads" . DIRECTORY_SEPARATOR . "temp";
             if (!is_dir($destination_path)) {
                 // no folder exits. Create the folder
                 mkdir($destination_path, 0775);
             }
             $thefilename = $destination_path . DIRECTORY_SEPARATOR . $currenttime_file;
         }
         // check if this is an ajax request
         if (!isset($_SERVER['HTTP_X_REQUESTED_WITH'])) {
             $error = "<span class='alert alert-danger blocked'>Error: No Request received.</span>";
             $result = array('msg' => $error, 'result' => '');
             echo $error;
             exit;
         }
         // debugMessage('size '.$_FILES["FileInput"]["size"]);
         // validate maximum allowed size
         $size = $_FILES["FileInput"]["size"];
         if ($size > $config->uploads->docmaximumfilesize) {
             $error = "<span class='alert alert-danger blocked'>Error: Maximum allowed size exceeded.</span>";
             $result = array('msg' => $error, 'result' => '');
             echo $error;
             exit;
         }
         // validate allowed formats
         if (!in_array($File_Ext, $allowedformatsarray)) {
             $error = "<span class='alert alert-danger blocked'>Error: Format '." . $File_Ext . "' not supported. Formats allowed include '" . $config->uploads->docallowedformats . "'</span>";
             $result = array('msg' => $error, 'result' => '');
             echo $error;
             exit;
         }
         # move the file
         try {
             move_uploaded_file($_FILES['FileInput']['tmp_name'], $thefilename);
             // die('File '.$NewFileName.' Uploaded.');
             $result = array('oldfilename' => $oldfile, 'newfilename' => $currenttime_file, 'msg' => 'Successfully uploaded', 'result' => 1, 'filesize' => $size);
             // debugMessage($result);
             echo json_encode($result);
             exit;
         } catch (Exception $e) {
             $error = 'Error in uploading File ' . $File_Name . '. ' . $e->getMessage();
             $result = array('msg' => $error, 'result' => '');
             echo $error;
             exit;
         }
     }
     if (array_key_exists('submit', $formvalues) || array_key_exists('id', $formvalues)) {
         $this->_setParam('uploadedbyid', $session->getVar('userid'));
         $this->_setParam('dateuploaded', DEFAULT_DATETIME);
         $this->_setParam("action", ACTION_CREATE);
         if (!isArrayKeyAnEmptyString('id', $formvalues)) {
             $this->_setParam("action", ACTION_EDIT);
         }
         // debugMessage($formvalues); exit();
         parent::createAction();
     }
 }
Esempio n. 3
0
 function uploadAd()
 {
     $to_dir = PATHTODATADIR . "/" . $this->rec["marketplace_id"];
     if ($_FILES["ad_upload"]["name"] != "") {
         $name = $this->rec["id"];
         $file_name = "ad" . $name . findExtension("ad_upload");
         $this->saveFile($_FILES["ad_upload"]["tmp_name"], $to_dir, $file_name);
         $query_statement = "UPDATE `" . AD_TABLE_NAME . "` SET `file` = '" . $file_name . "' WHERE `id` = '" . $this->rec["id"] . "';";
         $query = mysql_query($query_statement);
     }
     return true;
 }
 function saveMedia()
 {
     $to_dir = PATHTODATADIR . "/" . $this->rec["record_id"];
     if ($_FILES["sponsor"]["name"] != "") {
         $name = "sponsor";
         $file_name = $name . ".jpg";
         $to_file = $to_dir . "/" . $file_name;
         $this->saveFile($_FILES[$name]["tmp_name"], $to_dir, $file_name);
     }
     if ($_FILES["gallery"]["name"] != "") {
         $name = "gallery_" . date("Ymdhis");
         $file_name = $name . findExtension("gallery");
         $to_file = $to_dir . "/" . $file_name;
         $this->saveFile($_FILES["gallery"]["tmp_name"], $to_dir, $file_name);
         $i++;
     }
     if ($_FILES["video"]["name"] != "") {
         $name = "video_" . date("Ymdhis");
         $file_name = $name . ".mov";
         $to_file = $to_dir . "/" . $file_name;
         $this->saveFile($_FILES["video"]["tmp_name"], $to_dir, $file_name);
     }
     if ($_POST["youtube"] != "") {
         $name = "youtube_" . date("Ymdhis");
         $file_name = $name . ".txt";
         $to_file = $to_dir . "/" . $file_name;
         $fopen = fopen($to_file, "w");
         fwrite($fopen, stripslashes($_POST["youtube"]));
         fclose($fopen);
     }
     if ($_FILES["bizlogo"]["name"] != "") {
         $name = "bizlogo";
         $file_name = $name . ".jpg";
         $to_file = $to_dir . "/" . $file_name;
         $this->saveFile($_FILES[$name]["tmp_name"], $to_dir, $file_name);
     }
     return $return;
 }
 public function processpictureAction()
 {
     // disable rendering of the view and layout so that we can just echo the AJAX output
     $this->_helper->layout->disableLayout();
     $this->_helper->viewRenderer->setNoRender(TRUE);
     $session = SessionWrapper::getInstance();
     $config = Zend_Registry::get("config");
     $this->_translate = Zend_Registry::get("translate");
     $formvalues = $this->_getAllParams();
     //debugMessage($this->_getAllParams());
     $user = new UserAccount();
     $user->populate(decode($this->_getParam('id')));
     // only upload a file if the attachment field is specified
     $upload = new Zend_File_Transfer();
     // set the file size in bytes
     $upload->setOptions(array('useByteString' => false));
     // Limit the extensions to the specified file extensions
     $upload->addValidator('Extension', false, $config->uploads->photoallowedformats);
     $upload->addValidator('Size', false, $config->uploads->photomaximumfilesize);
     // base path for profile pictures
     $destination_path = BASE_PATH . DIRECTORY_SEPARATOR . "uploads" . DIRECTORY_SEPARATOR . "users" . DIRECTORY_SEPARATOR . "user_";
     // determine if user has destination avatar folder. Else user is editing there picture
     if (!is_dir($destination_path . $user->getID())) {
         // no folder exits. Create the folder
         mkdir($destination_path . $user->getID(), 0777);
     }
     // set the destination path for the image
     $profilefolder = $user->getID();
     $destination_path = $destination_path . $profilefolder . DIRECTORY_SEPARATOR . "avatar";
     if (!is_dir($destination_path)) {
         mkdir($destination_path, 0777);
     }
     // create archive folder for each user
     $archivefolder = $destination_path . DIRECTORY_SEPARATOR . "archive";
     if (!is_dir($archivefolder)) {
         mkdir($archivefolder, 0777);
     }
     $oldfilename = $user->getProfilePhoto();
     //debugMessage($destination_path);
     $upload->setDestination($destination_path);
     // the profile image info before upload
     $file = $upload->getFileInfo('profileimage');
     $uploadedext = findExtension($file['profileimage']['name']);
     $currenttime = time();
     $currenttime_file = $currenttime . '.' . $uploadedext;
     $thefilename = $destination_path . DIRECTORY_SEPARATOR . 'base_' . $currenttime_file;
     $thelargefilename = $destination_path . DIRECTORY_SEPARATOR . 'large_' . $currenttime_file;
     $updateablefile = $destination_path . DIRECTORY_SEPARATOR . 'base_' . $currenttime;
     $updateablelarge = $destination_path . DIRECTORY_SEPARATOR . 'large_' . $currenttime;
     //debugMessage($thefilename);
     // rename the base image file
     $upload->addFilter('Rename', array('target' => $thefilename, 'overwrite' => true));
     // exit();
     // process the file upload
     if ($upload->receive()) {
         // debugMessage('Completed');
         $file = $upload->getFileInfo('profileimage');
         // debugMessage($file);
         $basefile = $thefilename;
         // convert png to jpg
         if (in_array(strtolower($uploadedext), array('png', 'PNG', 'gif', 'GIF'))) {
             ak_img_convert_to_jpg($thefilename, $updateablefile . '.jpg', $uploadedext);
             unlink($thefilename);
         }
         $basefile = $updateablefile . '.jpg';
         // new profilenames
         $newlargefilename = "large_" . $currenttime_file;
         // generate and save thumbnails for sizes 250, 125 and 50 pixels
         resizeImage($basefile, $destination_path . DIRECTORY_SEPARATOR . 'large_' . $currenttime . '.jpg', 400);
         resizeImage($basefile, $destination_path . DIRECTORY_SEPARATOR . 'medium_' . $currenttime . '.jpg', 165);
         // unlink($thefilename);
         unlink($destination_path . DIRECTORY_SEPARATOR . 'base_' . $currenttime . '.jpg');
         // exit();
         // update the user with the new profile images
         try {
             $user->setProfilePhoto($currenttime . '.jpg');
             $user->save();
             // check if user already has profile picture and archive it
             $ftimestamp = current(explode('.', $user->getProfilePhoto()));
             $allfiles = glob($destination_path . DIRECTORY_SEPARATOR . '*.*');
             $currentfiles = glob($destination_path . DIRECTORY_SEPARATOR . '*' . $ftimestamp . '*.*');
             // debugMessage($currentfiles);
             $deletearray = array();
             foreach ($allfiles as $value) {
                 if (!in_array($value, $currentfiles)) {
                     $deletearray[] = $value;
                 }
             }
             // debugMessage($deletearray);
             if (count($deletearray) > 0) {
                 foreach ($deletearray as $afile) {
                     $afile_filename = basename($afile);
                     rename($afile, $archivefolder . DIRECTORY_SEPARATOR . $afile_filename);
                 }
             }
             $session->setVar(SUCCESS_MESSAGE, $this->_translate->translate("global_update_success"));
             $this->_helper->redirector->gotoUrl($this->view->baseUrl("profile/picture/id/" . encode($user->getID()) . '/crop/1'));
         } catch (Exception $e) {
             $session->setVar(ERROR_MESSAGE, $e->getMessage());
             $session->setVar(FORM_VALUES, $this->_getAllParams());
             $this->_helper->redirector->gotoUrl($this->view->baseUrl('profile/picture/id/' . encode($user->getID())));
         }
     } else {
         // debugMessage($upload->getMessages());
         $uploaderrors = $upload->getMessages();
         $customerrors = array();
         if (!isArrayKeyAnEmptyString('fileUploadErrorNoFile', $uploaderrors)) {
             $customerrors['fileUploadErrorNoFile'] = "Please browse for image on computer";
         }
         if (!isArrayKeyAnEmptyString('fileExtensionFalse', $uploaderrors)) {
             $custom_exterr = sprintf($this->_translate->translate('global_invalid_ext_error'), $config->uploads->photoallowedformats);
             $customerrors['fileExtensionFalse'] = $custom_exterr;
         }
         if (!isArrayKeyAnEmptyString('fileUploadErrorIniSize', $uploaderrors)) {
             $custom_exterr = sprintf($this->_translate->translate('global_invalid_size_error'), formatBytes($config->uploads->photomaximumfilesize, 0));
             $customerrors['fileUploadErrorIniSize'] = $custom_exterr;
         }
         if (!isArrayKeyAnEmptyString('fileSizeTooBig', $uploaderrors)) {
             $custom_exterr = sprintf($this->_translate->translate('global_invalid_size_error'), formatBytes($config->uploads->photomaximumfilesize, 0));
             $customerrors['fileSizeTooBig'] = $custom_exterr;
         }
         $session->setVar(ERROR_MESSAGE, 'The following errors occured <ul><li>' . implode('</li><li>', $customerrors) . '</li></ul>');
         $session->setVar(FORM_VALUES, $this->_getAllParams());
         $this->_helper->redirector->gotoUrl($this->view->baseUrl('profile/picture/id/' . encode($user->getID())));
     }
     // exit();
 }