Example #1
0
 public function upload()
 {
     global $varChecker;
     if ($varChecker->getValue('fileindex') !== false) {
         $fileindex = $varChecker->getValue('fileindex');
         $fileindex = empty($fileindex) ? 0 : $fileindex;
         $handle = $this->findFilehandle($fileindex);
     } else {
         $handle = $this->findFilehandle();
     }
     $uploader = new FileUploader($handle, true);
     $error = '';
     $path = 'cache/templates/' . $this->INK_User->getCustomer()->getSite()->getId() . '/';
     $fmaker = new FileMaker();
     $fmaker->makeDirectory($path, false);
     //upload the file
     try {
         //upload to cms
         $path = $uploader->upload($path);
         //upload to client server
         $result = array('success' => 'file_uploaded', 'filepath' => $path, 'msg' => 'file uploaded');
     } catch (Exception $e) {
         $result = array('error' => $e->getMessage());
     }
     echo json_encode($result);
 }
function header_image()
{
    $header_image_action = $_POST['header_image_option'];
    $display_header_image = $_POST['desktop_image_display'];
    if (!empty($_FILES['headerphoto']['name']) && empty($_POST['restore_default'])) {
        $uploadfile = PA::$upload_path . basename($_FILES['headerphoto']['name']);
        $myUploadobj = new FileUploader();
        //creating instance of file.
        $image_type = 'image';
        $file = $myUploadobj->upload_file(PA::$upload_path, 'headerphoto', true, true, $image_type);
        if ($file == false) {
            throw new PAException(GROUP_PARAMETER_ERROR, "File upload error: " . $myUploadobj->error);
        }
        $header_image = $file;
        $header_img = array('display_header_image' => $display_header_image, 'header_image_action' => $header_image_action, 'header_image' => $header_image);
        return $header_img;
    }
    if (isset($_POST['restore_default'])) {
        $header_image = NULL;
        $header_img = array('display_header_image' => $display_header_image, 'header_image_action' => $header_image_action, 'header_image' => $header_image);
        return $header_img;
    }
    $header_img = array('display_header_image' => $display_header_image, 'header_image_action' => $header_image_action);
    return $header_img;
}
Example #3
0
 public function changeSlide($fileName)
 {
     // folder for uploaded files
     $tempFolder = Yii::app()->basePath . DIRECTORY_SEPARATOR . '..' . Yii::app()->params['folders']['temp'];
     if (!is_writable($tempFolder)) {
         throw new CException('temporary folder is not exists or not writable. Path:' . $tempFolder);
     }
     $uploader = new FileUploader(Yii::app()->params['uploader']['allowedFileExtensions'], Yii::app()->params['uploader']['sizeLimit']);
     $result = $uploader->handleUpload($tempFolder);
     if (!isset($result['error'])) {
         $imageHandler = new CImageHandler();
         $imageHandler->load($tempFolder . $result['filename']);
         try {
             $imageHandler->cropAndScaleFromCenter(1040, 380);
             $imageHandler->save($this->getSliderImagePath($fileName));
             $this->response = array('fileName' => $fileName, 'imageSrc' => $this->getSliderImageSrc($fileName));
             return TRUE;
         } catch (CException $e) {
             $this->response = array('errorMessage' => $fileName . $e->getMessage());
             return FALSE;
         }
     } else {
         $this->response = array('errorMessage' => $result['error']);
         return FALSE;
     }
 }
Example #4
0
 function handle_uploaded_avatar_pic()
 {
     if (!empty($_FILES['userfile']['name'])) {
         $uploadfile = PA::$upload_path . basename($_FILES['userfile']['name']);
         $myUploadobj = new FileUploader();
         //creating instance of file.
         $image_type = 'image';
         $file = $myUploadobj->upload_file(PA::$upload_path, 'userfile', true, true, $image_type);
         if ($file == false) {
             $this->reg_user->msg = $myUploadobj->error;
             $this->reg_user->error = TRUE;
         } else {
             $_POST['user_filename'] = $file;
         }
     } else {
         // IF THE UPLOAD FIELD WAS EMPTY CHECK FOR THE URL FIELD
         $avatar_url = trim(@$_REQUEST['avatar_url']);
         if (!empty($avatar_url) && preg_match("|http://(.*?)/(.*)|", $avatar_url, $m)) {
             //TODO: change to use FileUploader or new storage code.
             list(, $uf_server, $uf_path) = $m;
             $uf_basename = preg_replace("[^A-Za-z0-9\\-_\\.]", "_", basename($uf_path));
             //FETCH THE IMAGE VIA HTTP AND WRITE IT WHERE AN UPLOADED FILE WOULD GO
             $uploadfile = PA::$upload_path . $uf_basename;
             if ($this->reg_user->download($avatar_url, $uploadfile)) {
                 $_POST['user_filename'] = $uf_basename;
                 $_POST['avatar_url'] = '';
             } else {
                 $this->reg_user->msg = "Could not retrieve file from URL:" . $avatar_url;
                 $this->reg_user->error = TRUE;
             }
         }
     }
 }
 function handle_uploaded_avatar_pic()
 {
     if (isset($_POST['user_filename'])) {
         $_POST['user_filename'] = Storage::validateFileId($_POST['user_filename']);
     }
     if (!empty($_FILES['userfile']['name'])) {
         // process uploaded image file
         $myUploadobj = new FileUploader();
         $file = $myUploadobj->upload_file(PA::$upload_path, 'userfile', true, true, 'image');
         if (!$file) {
             throw new PAException(FILE_NOT_UPLOADED, $myUploadobj->error);
         }
     } else {
         // download given image url
         $avatar_url = trim(@$_REQUEST['avatar_url']);
         if (!empty($avatar_url) && preg_match("|http://(.*?)/(.*)|", $avatar_url, $m)) {
             list(, $uf_server, $uf_path) = $m;
             $file = Storage::save($avatar_url, basename($uf_path), "critical", "image");
             if (!$file) {
                 throw new PAException(FILE_NOT_UPLOADED, sprintf(__("Could not retrieve file from URL: %s"), $avatar_url));
             }
         }
     }
     if (@$file) {
         $_POST['user_filename'] = $file;
         $_POST['avatar_url'] = '';
     }
 }
 function upload_file()
 {
     $name = $_FILES['file']['name'];
     $file = $_FILES['file'];
     $fileUploader = new FileUploader($file, $name);
     $json = $fileUploader->uploadFile();
     echo $json;
 }
function do_file_upload()
{
    $uploadfile = PA::$upload_path . basename($_FILES['network_image']['name']);
    $myUploadobj = new FileUploader();
    //creating instance of file.
    $image_type = 'image';
    $file = $myUploadobj->upload_file(PA::$upload_path, 'network_image', true, true, $image_type);
    if ($file == false) {
        $r = array('error' => TRUE, 'error_msg' => $myUploadobj->error);
    } else {
        $r = array('error' => FALSE, 'file' => $file);
    }
    return $r;
}
Example #8
0
 public function init()
 {
     $this->events = array_merge($this->events, array('success' => '$.fn.yiiListView.update("history")'));
     $this->mediaParams['associationType'] = $this->associationType;
     $this->mediaParams['associationId'] = $this->associationId;
     parent::init();
 }
 public static function getInstance()
 {
     if (!self::$_instance instanceof self) {
         self::$_instance = new self();
     }
     return self::$_instance;
 }
Example #10
0
 /**
  * 更新LOGO
  *
  * @return bool
  */
 public function updateLogo()
 {
     if (!isset($_FILES['qqfile'])) {
         return true;
     }
     $uploader = new FileUploader();
     $result = $uploader->handleUpload('brand');
     if (isset($result['success'])) {
         if ($this->id_image > 0) {
             $image = new Image($this->id_image);
             if (Validate::isLoadedObject($image)) {
                 $image->delete();
             }
         }
         $this->id_image = $result['success']['id_image'];
         return $this->update();
     }
     return false;
 }
 /**
  * Upload media file ,like: image/flash
  *
  * @author  John.meng (цот╤РШ)
  * @since   version - 2006-1-7 12:56:23
  * @param   string  
  *
  */
 function uploadMedia($CurrentUserPathImages, $oldPic = "", $PicType = "Pic", $newWidth = "", $newHeight = "", $CreateIco = false, $IcoWidth = "", $IcoHeight = "")
 {
     $allowed_mimetypes = array('image/gif', 'image/jpeg', 'image/pjpeg', 'image/x-png', 'application/x-shockwave-flash');
     $maxfilesize = 10000000;
     $FileUploaderObj = new FileUploader($CurrentUserPathImages, $allowed_mimetypes, $maxfilesize);
     $FileUploaderObj->newWidth = $newWidth;
     $FileUploaderObj->newHeight = $newHeight;
     if ($CreateIco && $IcoWidth && $IcoHeight) {
         $FileUploaderObj->CreateIco = $CreateIco;
         $FileUploaderObj->IcoWidth = $IcoWidth;
         $FileUploaderObj->IcoHeight = $IcoHeight;
     }
     if ($_FILES[$PicType]['name'] != "") {
         if ($FileUploaderObj->fetchMedia($PicType)) {
             $FileUploaderObj->setPrefix($PicType . "_");
             if (!$FileUploaderObj->upload()) {
                 echo $FileUploaderObj->getErrors();
             } else {
                 $StrPic = $FileUploaderObj->getSavedFileName();
                 if ($oldPic) {
                     @unlink($CurrentUserPathImages . "/" . $oldPic);
                 }
             }
         }
     } else {
         $StrPic = $oldPic;
     }
     return $StrPic;
 }
Example #12
0
/**
 * 上传图片并更新排序
 */
function ajaxProcessAddImage()
{
    // max file size in bytes
    $uploader = new FileUploader();
    $result = $uploader->handleUpload(ImageType::IMAGE_PRDOCUT);
    if (isset($result['success'])) {
        $image = $result['success'];
        $row['id_product'] = Tools::Q('id_product');
        $row['id_image'] = (int) $image['id_image'];
        $row['position'] = (int) Product::getImageLastPosition($row['id_product']);
        if ($row['position'] == 1) {
            $row['cover'] = 1;
        } else {
            $row['cover'] = 0;
        }
        Db::getInstance()->insert(DB_PREFIX . 'product_to_image', $row);
        $json = array('status' => 'ok', 'id' => $row['id_image'], 'path' => Image::getImageLink($row['id_image'], 'small'), 'position' => $row['position'], 'cover' => $row['cover']);
        die(json_encode($json));
    } else {
        die(json_encode($result));
    }
}
Example #13
0
 public static function uploadFileLocal($fieldName, $fileName = null)
 {
     $fileInfo = self::getFileInfo($fieldName);
     if ($fileInfo === null) {
         return null;
     }
     // Upload all file to storage directory. Its temporary.
     $type = 'files';
     $uploadedFileName = $fileName == null ? $fileInfo->getName() : $fileName;
     $dstPath = FileUploader::getStorageDirectory($type) . $uploadedFileName;
     if (!$fileInfo->saveAs($dstPath)) {
         return null;
     }
     return $type . '/' . $uploadedFileName;
 }
 public function run()
 {
     // folder for uploaded files
     $tempFolder = Yii::app()->basePath . DIRECTORY_SEPARATOR . '..' . $this->tempFolder;
     if (!is_writable($tempFolder)) {
         throw new CException('temporary folder is not exists or not writable. Path:' . $tempFolder);
     }
     $uploader = new FileUploader($this->allowedFileExtensions, $this->fileLimit);
     $result = $uploader->handleUpload($tempFolder);
     if (!isset($result['error'])) {
         $imageHandler = new CImageHandler();
         $imageHandler->load($tempFolder . $result['filename']);
         try {
             // if min/max weight/height are set - check those conditions
             $this->validateImageDimensions($imageHandler->getWidth(), $imageHandler->getHeight());
             $this->getController()->successfulAjaxResponse(array('fileName' => $imageHandler->getBaseFileName(), 'imageSrc' => '/application' . $this->tempFolder . $imageHandler->getBaseFileName()));
         } catch (CException $e) {
             $errorMsg = $imageHandler->getBaseFileName() . ' - ' . $e->getMessage();
             $this->getController()->unsuccessfulAjaxResponse(array('errorMessage' => $errorMsg));
         }
     } else {
         $this->getController()->unsuccessfulAjaxResponse(array('errorMessage' => $result['error']));
     }
 }
Example #15
0
 /**
  * Set value of element
  *
  * @param mixed $value
  * @return mixed
  */
 function setValue($value)
 {
     if ($this->m_Deleteable == 'N') {
     } else {
         $delete_user_opt = BizSystem::clientProxy()->getFormInputs($this->m_Name . "_DELETE");
         if ($delete_user_opt) {
             $this->m_Value = "";
             return;
         } else {
             if (count($_FILES) > 0) {
             } else {
                 $this->m_Value = $value;
             }
         }
     }
     if (count($_FILES) > 0) {
         if (!$this->m_Uploaded) {
             $picFileName = parent::setValue($value);
             if ((int) $this->m_PicWidth > 0 || (int) $this->m_PicHeight > 0) {
                 //resize picture size
                 $fileName = $this->m_UploadRoot . $picFileName;
                 $width = $this->m_PicWidth;
                 $height = $this->m_PicHeight;
                 $quality = $this->m_PicQuality;
                 $this->resizeImage($fileName, $fileName, $width, $height, $quality);
             }
             if (((int) $this->m_ThumbWidth > 0 || (int) $this->m_ThumbHeight > 0) && $this->m_ThumbFolder != "") {
                 //generate thumbs picture
                 if (!is_dir($this->m_UploadRoot . $this->m_ThumbFolder)) {
                     mkdir($this->m_UploadRoot . $this->m_ThumbFolder, 0777, true);
                 }
                 $file = $_FILES[$this->m_Name];
                 $thumbPath = $this->m_ThumbFolder . "/thumbs-" . date("YmdHis") . "-" . urlencode($file['name']);
                 $thumbFileName = $this->m_UploadRoot . $thumbPath;
                 $width = $this->m_ThumbWidth;
                 $height = $this->m_ThumbHeight;
                 $quality = $this->m_ThumbQuality;
                 $this->resizeImage($fileName, $thumbFileName, $width, $height, $quality);
                 $result = array('picture' => $this->m_UploadRootURL . $picFileName, 'thumbpic' => $this->m_UploadRootURL . $thumbPath);
                 $this->m_Value = serialize($result);
             }
         }
     } else {
         $this->m_Value = $value;
     }
 }
 /**
  * 
  * @param array $file e.g. $_FILES['photo']
  * @return ConversationAttachment
  */
 public function addAttachment($file)
 {
     $systemFilename = self::findNewFileName($this->config->uploadDir);
     $attachsImgUpConfig = $this->config->imageUploaderConfig;
     $attachsImgUpConfig->uploadDir = $this->config->uploadDir;
     if (in_array($file["type"], $attachsImgUpConfig->acceptedMimeTypes->toArray())) {
         ImageUploader::upload($file, $systemFilename, $attachsImgUpConfig);
     } else {
         FileUploader::upload($file, $systemFilename, $this->config->uploadDir);
     }
     $qb = new QueryBuilder();
     $qb->insert(Tbl::get('TBL_CONVERSATION_ATTACHEMENTS'))->values(array('system_filename' => $systemFilename, 'filename' => $file['name'], 'mime_type' => $file['type']));
     $attachmentId = $this->query->exec($qb->getSQL())->getLastInsertId();
     $filter = new ConversationAttachmentFilter();
     $filter->setId($attachmentId);
     return $this->getAttachment($filter);
 }
Example #17
0
 /**
  * @copydoc FileUploader::upload
  *
  * @throws SystemException 'ERR_BAD_FILE_FORMAT'
  */
 public function upload($dir)
 {
     if ($this->getExtension() != 'flv' && file_exists($this->getConfigValue('video.ffmpeg'))) {
         $cmd = $this->getConfigValue('video.ffmpeg') . ' -i ' . $this->file['tmp_name'] . ' -f flv -y  -ar 22050 -ab 32 -b 700000 -s cif ' . ($this->FileObjectName = $this->generateFilename($dir, 'flv'));
         $returnStatus = false;
         /*$result = */
         system($cmd, $returnStatus);
         if ($returnStatus) {
             throw new SystemException('ERR_BAD_FILE_FORMAT', SystemException::ERR_CRITICAL, $this->file['name']);
         }
         $cmd = $this->getConfigValue('video.ffmpeg') . ' -i ' . $this->file['tmp_name'] . ' -vframes 1 -ss 00:00:05' . ' -f image2 -s cif -an ' . $this->FileObjectName . '.jpg';
         system($cmd);
         $result = true;
     } else {
         $result = parent::upload($dir);
     }
     return $result;
 }
                 }
             }
         }
     }
 }
 //code for fields which are common to some sections like description, image
 if ($section == 'video_tours' || $section == 'register_today' || $section == 'network_of_moment' || $section == 'server_announcement' || $section == 'showcase') {
     if (empty($_POST['description'])) {
         $message[] = __('No description provided for network of moment');
     } else {
         $networks_data['description'] = $_POST['description'];
     }
     $image_file = 'network_image';
     if (!empty($_FILES[$image_file]['name'])) {
         //validating and then uploading the network image.
         $uploader = new FileUploader();
         //creating instance of file.
         $file = $uploader->upload_file(PA::$upload_path, $image_file, true, true, 'image');
         if ($file == false) {
             $message[] = __(' For network of moment, ') . $uploader->error;
             $networks_data['network_image'] = null;
         } else {
             $networks_data['network_image'] = $file;
         }
     } else {
         if (!empty($_POST['current_network_image'])) {
             //getting the previously added image from the hidden form field.
             $networks_data['network_image'] = $_POST['current_network_image'];
         } else {
             //setting the image to null.
             $networks_data['network_image'] = null;
 function initializeModule($request_method, $request_data)
 {
     global $error_msg;
     $error = false;
     $msg = array();
     $form_data = NULL;
     $edit = false;
     $message = NULL;
     // check permissions!
     $user_may = false;
     $user_may = PermissionsHandler::can_user(PA::$login_uid, array('permissions' => 'manage_ads'));
     // check for manageads of group permissions
     if (!empty($_REQUEST['gid']) && !$user_may) {
         // we do this checl only if the user is not already permitted to manage ads
         $gp_access = PermissionsHandler::can_group_user(PA::$login_uid, $_REQUEST['gid'], array('permissions' => 'manage_ads'));
         $user_may = $gp_access;
     }
     if (!$user_may) {
         $error_msg = __("You do not have permission to manage Ads.");
         return "skip";
     }
     // paging
     if (!empty($request_data['page'])) {
         $this->Paging["page"] = (int) $request_data['page'];
     }
     if (!empty($request_data['action']) && $request_data['action'] == 'edit' && !empty($request_data['ad_id'])) {
         $edit = TRUE;
         $res = Advertisement::get($params = NULL, $condition = array('ad_id' => (int) $request_data['ad_id']));
         if (!empty($res)) {
             $form_data['ad_id'] = $res[0]->ad_id;
             $form_data['ad_image'] = $res[0]->ad_image;
             $form_data['ad_script'] = $res[0]->ad_script;
             $form_data['ad_url'] = $res[0]->url;
             $form_data['ad_title'] = $res[0]->title;
             $form_data['ad_description'] = $res[0]->description;
             $form_data['ad_page_id'] = $res[0]->page_id;
             $form_data['orientation'] = $res[0]->orientation;
             $form_data['created'] = $res[0]->created;
         }
     } else {
         if (!empty($request_data['action']) && $request_data['action'] == 'delete' && !empty($request_data['ad_id'])) {
             if (!empty($request_data['ad_id'])) {
                 try {
                     Advertisement::delete((int) $request_data['ad_id']);
                     $error_msg = 19013;
                 } catch (CNException $e) {
                     $msg[] = $e->message;
                 }
             }
         } else {
             if (!empty($request_data['action']) && !empty($request_data['ad_id'])) {
                 $update = false;
                 switch ($request_data['action']) {
                     case 'disable':
                         $field_value = DELETED;
                         $msg_id = 19010;
                         $update = true;
                         break;
                     case 'enable':
                         $field_value = ACTIVE;
                         $msg_id = 19011;
                         $update = true;
                         break;
                 }
                 if ($update) {
                     $update_fields = array('is_active' => $field_value);
                     $condition = array('ad_id' => $request_data['ad_id']);
                     try {
                         Advertisement::update($update_fields, $condition);
                         $error_msg = $msg_id;
                     } catch (CNException $e) {
                         $msg[] = $e->message;
                     }
                 }
             }
         }
     }
     $advertisement = new Advertisement();
     if (!$error && $request_method == 'POST' && $request_data['btn_apply_name']) {
         // if page is submitted
         if (!empty($request_data['ad_id'])) {
             $advertisement->ad_id = $request_data['ad_id'];
             $advertisement->created = $request_data['created'];
             $msg_id = 19007;
         } else {
             $msg_id = 19008;
             $advertisement->created = time();
         }
         if (!empty($_FILES['ad_image']['name'])) {
             $filename = $_FILES['ad_image']['name'];
             $uploadfile = PA::$upload_path . basename($filename);
             $myUploadobj = new FileUploader();
             $file = $myUploadobj->upload_file(PA::$upload_path, 'ad_image', TRUE, TRUE, 'image');
             $advertisement->ad_image = $form_data['ad_image'] = $file;
             if ($file == FALSE) {
                 $error = TRUE;
                 $msg[] = $myUploadobj->error;
             }
         } else {
             if (!empty($request_data['ad_id'])) {
                 $advertisement->ad_image = $request_data['edit_image'];
             }
         }
         if (empty($request_data['ad_url']) && empty($request_data['ad_script'])) {
             $error = TRUE;
             $msg[] = MessagesHandler::get_message(19012);
         }
         if (!empty($request_data['ad_url'])) {
             // if url is given then validate
             $request_data['ad_url'] = Validation::validate_url($request_data['ad_url']);
             if (!Validation::isValidURL($request_data['ad_url'])) {
                 $error = TRUE;
                 $msg[] = MessagesHandler::get_message(19009);
             }
         }
         $advertisement->user_id = PA::$login_uid;
         $advertisement->url = $form_data['ad_url'] = $request_data['ad_url'];
         $advertisement->ad_script = $form_data['ad_script'] = $request_data['ad_script'];
         $advertisement->title = $form_data['ad_title'] = $request_data['ad_title'];
         $advertisement->description = $form_data['ad_description'] = $request_data['ad_description'];
         $advertisement->page_id = $form_data['ad_page_id'] = $request_data['ad_page_id'];
         $advertisement->orientation = $form_data['orientation'] = $request_data['x_loc'] . ',' . $request_data['y_loc'];
         $advertisement->changed = time();
         $advertisement->is_active = ACTIVE;
         if (!empty($_REQUEST['gid'])) {
             $advertisement->group_id = (int) $_REQUEST['gid'];
         }
         if (!$error) {
             try {
                 $ad_id = $advertisement->save();
                 if (!empty($file)) {
                     Storage::link($file, array("role" => "ad", "ad" => $ad_id));
                 }
                 $error_msg = $msg_id;
             } catch (CNException $e) {
                 $error_msg = $e->message;
             }
         } else {
             $error_msg = implode("<br/>", $msg);
         }
     }
     $this->form_data = $form_data;
     $this->edit = $edit;
     $this->message = $message;
 }
function create_new_network($_form)
{
    // function checks initial settings for network creation
    $can_network_be_created = Network::can_network_be_created();
    if ($can_network_be_created['error'] == TRUE) {
        $config_error = TRUE;
        $error = TRUE;
        $error_msg = $can_network_be_created['error_msg'];
    } else {
        if (!PA::$login_uid) {
            $config_error = TRUE;
        }
    }
    //form_data is array used for form fields
    // its initialized by $_form
    $temp_data['action'] = 'add';
    $vartoset = array('address', 'name', 'tagline', 'category', 'desc', 'header_image', 'header_image_option', 'action', 'type', 'network_group_title', 'network_content_moderation');
    for ($i = 0; $i < count($vartoset); $i += 1) {
        $var = $vartoset[$i];
        if (!empty($_form[$var])) {
            $temp_data[$var] = trim($_form[$var]);
        }
        if ($var == 'type') {
            if (isset($_form[$var])) {
                $temp_data[$var] = $_form[$var];
            }
        }
    }
    if (empty($config_error)) {
        filter_all_post($_form);
        //filters all data of html
        $error_post = check_error();
        //validation check
        if ($error_post['error'] == TRUE) {
            $error = TRUE;
            $error_msg = $error_post['error_msg'];
        }
        if (!$error_post) {
            //upload file
            if (!empty($_FILES['network_image']['name'])) {
                $file_upload_result = do_file_upload();
                if ($file_upload_result['error']) {
                    $error = TRUE;
                    $error_msg = $file_upload_result['error_msg'];
                } else {
                    $header_image = $network_image = $file_upload_result['file'];
                }
            } else {
                //image hidden
                $header_image = $network_image = @$temp_data['header_image'];
            }
            //code to upload the icon image
            if (!empty($_FILES['inner_logo_image']['name'])) {
                $uploadfile = PA::$upload_path . basename($_FILES['inner_logo_image']['name']);
                $myUploadobj = new FileUploader();
                //creating instance of file.
                $image_type = 'image';
                $file = $myUploadobj->upload_file(PA::$upload_path, 'inner_logo_image', true, true, $image_type);
                if ($file == false) {
                    $error = TRUE;
                    $error_msg = $file_upload_result['error_msg'];
                    unset($data_icon_image);
                } else {
                    $data_icon_image = array('inner_logo_image' => $file);
                }
            } else {
                unset($data_icon_image);
            }
            //...code to upload the icon image
            $network_basic_controls = PA::$network_defaults;
            $network_basic_controls['basic']['header_image']['name'] = $header_image;
            $network_basic_controls['basic']['header_image']['option'] = @$_form['header_image_option'] ? $_form['header_image_option'] : DESKTOP_IMAGE_ACTION_STRETCH;
            // for title of network group
            $network_basic_controls['network_group_title'] = '';
            $network_basic_controls['network_group_title'] = $_form['network_group_title'];
            $network_basic_controls['network_content_moderation'] = @$_form['network_content_moderation'];
            $temp_data['address'] = strtolower($temp_data['address']);
            $data = array('user_id' => $_SESSION['user']['id'], 'name' => strip_tags($temp_data['name']), 'address' => $temp_data['address'], 'tagline' => strip_tags($temp_data['tagline']), 'category_id' => $temp_data['category'], 'type' => $temp_data['type'], 'description' => $temp_data['desc'], 'extra' => serialize($network_basic_controls), 'created' => time(), 'changed' => time());
            //add icon image
            if (!empty($data_icon_image['inner_logo_image'])) {
                $data = array_merge($data, $data_icon_image);
                $temp_data['inner_logo_image'] = $data_icon_image['inner_logo_image'];
            }
            $network = new Network();
            $network->set_params($data);
            try {
                $nid = $network->save();
                //default_page_setting($network->address); // populate page_default setting
            } catch (PAException $e) {
                $error = TRUE;
                $error_msg = "{$e->message}";
            }
            if (!empty($nid)) {
                $_extra = serialize(array('user' => true, 'network' => true, 'groups' => array()));
                Roles::set_user_role_for_network($network->user_id, ADMINISTRATOR_ROLE, $network->address, $_extra);
                $location = "http://" . $temp_data['address'] . '.' . PA::$domain_suffix . BASE_URL_REL . PA_ROUTE_CONFIGURE_NETWORK;
            }
        }
        $msg_array = array();
        $msg_array['failure_msg'] = @$error_msg;
        $msg_array['success_msg'] = 7006;
        $return_array = @array('msg' => $msg_array, 'redirection_url' => $location, 'query_str' => $query_str);
    }
    return $return_array;
}
Example #21
0
<?php

$type = array_key_exists('type', $_POST) ? $_POST['type'] : null;
$marker = array_key_exists('marker', $_POST) ? $_POST['marker'] : null;
if (!$type) {
    die('Bad type given.');
}
//MD5_STR_LENGTH ещё использовать нельзя, так как Defines не подключен
if (!$marker || strlen($marker) <= 32) {
    die('Bad marker given.');
}
$sessionId = substr($marker, 32);
session_id($sessionId);
require_once 'AjaxTools.php';
check_user_session_marker($marker);
try {
    FileUploader::inst($type)->assertAutonomous();
    FileUploader::inst($type)->saveUploadedFile(true, null, $_POST);
} catch (Exception $ex) {
    PsLogger::inst('AjaxFileUpload')->info('Ошибка загрузки файла');
    PsLogger::inst('AjaxFileUpload')->info($ex->getTraceAsString());
    ExceptionHandler::dumpError($ex);
}
 //filters all data of html
 for ($i = 0; $i < count($vartoset); $i += 1) {
     $var = $vartoset[$i];
     if (!empty($_POST[$var])) {
         $form_data[$var] = $_POST[$var];
     }
 }
 if ($error == FALSE) {
     $newuser->login_name = $login_name;
     $newuser->password = $password;
     $newuser->first_name = $first_name;
     $newuser->last_name = $last_name;
     $newuser->email = $email;
     $newuser->is_active = ACTIVE;
     if (!empty($_FILES['userfile']['name'])) {
         $myUploadobj = new FileUploader();
         //creating instance of file.
         $image_type = 'image';
         $file = $myUploadobj->upload_file(PA::$upload_path, 'userfile', true, true, $image_type);
         if ($file == false) {
             $msg = $myUploadobj->error;
             $error = TRUE;
         } else {
             $newuser->picture = $file;
         }
     }
     if ($error == FALSE) {
         try {
             $newuser->save();
             if (!empty($file)) {
                 Storage::link($file, array("role" => "avatar", "user" => $newuser->user_id));
Example #23
0
 /**
  * Upload and apply new avatar
  * @return bool
  * @throws CException
  */
 public function changeAvatar()
 {
     // folder for uploaded files
     $tempFolder = Yii::app()->basePath . DIRECTORY_SEPARATOR . '..' . Yii::app()->params['folders']['temp'];
     $avatarsFolder = Yii::app()->basePath . DIRECTORY_SEPARATOR . '..' . Yii::app()->params['folders']['userAvatars'];
     if (!is_writable($tempFolder)) {
         throw new CException('temporary folder is not exists or not writable. Path:' . $tempFolder);
     }
     // Upload to temp folder
     $uploader = new FileUploader(Yii::app()->params['uploader']['allowedFileExtensions'], Yii::app()->params['uploader']['sizeLimit']);
     $result = $uploader->handleUpload($tempFolder);
     if (!isset($result['error'])) {
         // Move file to target folder and make thumbs
         $imageHandler = new CImageHandler();
         $imageHandler->load($tempFolder . $result['filename']);
         try {
             $imageHandler->save($avatarsFolder . $result['filename']);
             $imageHandler->cropAndScaleFromCenter(self::SMALL_THUMB_WIDTH, self::SMALL_THUMB_HEIGHT);
             $imageHandler->save($avatarsFolder . self::THUMB_PREFIX_SMALL . $result['filename']);
             $imageHandler->load($tempFolder . $result['filename']);
             $imageHandler->cropAndScaleFromCenter(self::MICRO_THUMB_WIDTH, self::MICRO_THUMB_HEIGHT);
             $imageHandler->save($avatarsFolder . self::THUMB_PREFIX_MICRO . $result['filename']);
             if ($this->hasPhoto()) {
                 $this->_removeOldPhoto();
             }
             $this->photo = $result['filename'];
             $this->_response = array('originalSrc' => $this->getOriginalPhoto(), 'thumbSrc' => $this->getSmallThumbnail());
             $this->save(FALSE);
             return TRUE;
         } catch (CException $e) {
             $this->_response = array('errorMessage' => $e->getMessage());
             return FALSE;
         }
     } else {
         $this->_response = array('errorMessage' => $result['error']);
         return FALSE;
     }
 }
 public function ajaxProcessAddImage()
 {
     self::$currentIndex = 'index.php?tab=AdminProducts';
     $allowedExtensions = array('jpeg', 'gif', 'png', 'jpg');
     // max file size in bytes
     $uploader = new FileUploader($allowedExtensions, $this->max_image_size);
     $result = $uploader->handleUpload();
     if (isset($result['success'])) {
         $obj = new Image((int) $result['success']['id_image']);
         // Associate image to shop from context
         $shops = Shop::getContextListShopID();
         $obj->associateTo($shops);
         $json_shops = array();
         foreach ($shops as $id_shop) {
             $json_shops[$id_shop] = true;
         }
         $json = array('name' => $result['success']['name'], 'status' => 'ok', 'id' => $obj->id, 'path' => $obj->getExistingImgPath(), 'position' => $obj->position, 'cover' => $obj->cover, 'shops' => $json_shops);
         @unlink(_PS_TMP_IMG_DIR_ . 'product_' . (int) $obj->id_product . '.jpg');
         @unlink(_PS_TMP_IMG_DIR_ . 'product_mini_' . (int) $obj->id_product . '_' . $this->context->shop->id . '.jpg');
         die(Tools::jsonEncode($json));
     } else {
         die(Tools::jsonEncode($result));
     }
 }
 /**
  * @inheritdoc
  */
 public function __construct($fileHolderKey)
 {
     parent::__construct($fileHolderKey);
     $this->addFileUploadDirectory(FileManager::IMAGE_DIR);
 }
 if ($network_info->type == MOTHER_NETWORK_TYPE) {
     $skip_check = array('address', 'category');
 } else {
     $skip_check = array('address');
 }
 $error_post = check_error($skip_check);
 //validation check
 if ($error_post['error'] == TRUE) {
     $error = TRUE;
     $error_msg = $error_post['error_msg'];
 }
 if (!$error_post) {
     //code to upload the icon image
     if (!empty($_FILES['inner_logo_image']['name'])) {
         $uploadfile = $uploaddir . basename($_FILES['inner_logo_image']['name']);
         $myUploadobj = new FileUploader();
         //creating instance of file.
         $image_type = 'image';
         $file = $myUploadobj->upload_file($uploaddir, 'inner_logo_image', true, true, $image_type);
         if ($file == false) {
             $error = TRUE;
             $error_msg = $file_upload_result['error_msg'];
             unset($data_icon_image);
         } else {
             $data_icon_image = array('inner_logo_image' => $file);
         }
     } else {
         unset($data_icon_image);
     }
     //...code to upload the icon image
     $network_basic_controls = $extra;
                break;
            case '7':
                $error = 'Failed to write file to disk';
                break;
            case '8':
                $error = 'File upload stopped by extension';
                break;
            case '999':
            default:
                $error = 'No error code avaiable';
        }
    } elseif (empty($_FILES['userfile']['tmp_name']) || $_FILES['userfile']['tmp_name'] == 'none') {
        $error = 'No file was uploaded..';
    } else {
        try {
            $myUploadobj = new FileUploader();
            $image_file = $myUploadobj->upload_file(PA::$upload_path, 'userfile', true, true, 'image');
            if (!$image_file) {
                $error = $myUploadobj->error;
            }
        } catch (Exception $e) {
            $error = $e->getMessage();
        }
        $img_resized = uihelper_resize_mk_img($image_file, 200, 200, NULL, 'style="margin-left: 10px"');
    }
    echo "{";
    echo "error: '" . $error . "',\n";
    echo "image: '" . htmlspecialchars($img_resized) . "',\n";
    echo "image_file: '" . $image_file . "'\n";
    echo "}";
} else {
<?php

include "includes.php";
$id = $_POST['id'];
$filePath = $_POST['filePath'];
$name = isset($_POST['name']) ? $_POST['name'] : null;
$description = isset($_POST['description']) ? $_POST['description'] : null;
$preview = $_POST['preview'];
$thumb = $_POST['thumb'];
$downloads = $_POST['downloads'];
$path;
if (!$id) {
    $file = $_FILES['upload'];
    $fileUploader = new FileUploader($file, $name, $description);
    $id = $fileUploader->uploadFile();
} else {
    $file = new File($filePath, $name, $description, $downloads, $preview, $thumb, $id);
    $file->update();
    header("Location: /admin/files/" . $id);
    exit;
}
function uihelper_upload_gallery_for_group($uid, $type, $k = 0)
{
    require_once "api/User/User.php";
    require_once "api/Tag/Tag.php";
    require_once "api/Album/Album.php";
    require_once "api/Image/Image.php";
    require_once "api/Audio/Audio.php";
    require_once "api/Video/Video.php";
    require_once "web/includes/classes/CNFileUploader.php";
    $logged_in_user = get_login_user();
    $user = new User();
    $media_count_no = $k;
    $error_file = NULL;
    $uploaded = False;
    if ($type == '') {
        $file_type = "image";
        $alb_type = IMAGE_ALBUM;
        $new_img = new Image();
        $new_img->file_perm = @$_POST['image_perm'];
    } elseif ($type == '_audio') {
        $file_type = "audio";
        $alb_type = AUDIO_ALBUM;
        $new_img = new Audio();
        $new_img->file_perm = @$_POST['audio_perm'];
    } elseif ($type == '_video') {
        $file_type = "video";
        $alb_type = VIDEO_ALBUM;
        $new_img = new Video();
        $new_img->file_perm = @$_POST['video_perm'];
    }
    //file uploading start
    $file_name_dynamic = "userfile{$type}" . "_" . "{$k}";
    $file_name_dynamic_type = $file_name_dynamic;
    //"$file_name_dynamic"."$type";
    $newname = $_FILES[$file_name_dynamic_type]['name'];
    $uploadfile = PA::$upload_path . basename($_FILES[$file_name_dynamic_type]['name']);
    $myUploadobj = new FileUploader();
    //creating instance of file.
    $image_type = "{$file_type}";
    $value = $file_name_dynamic_type;
    $file = $myUploadobj->upload_file(PA::$upload_path, $value, true, true, $image_type);
    if ($file == false) {
        $msg = $myUploadobj->error;
        $error = TRUE;
    } else {
        $new_img->file_name = "{$file}";
        $error_file = FALSE;
    }
    // file uploading end
    if (empty($error)) {
        try {
            $user->load((int) $uid);
            $action = !empty($_GET['action']) ? $_GET['action'] : 'upload';
            $colls = Album::load_all($uid, $alb_type);
            if (isset($_POST['submit' . $type]) && $action != 'delete' && $error_file == FALSE) {
                $new_img->author_id = $uid;
                if ($type == '_audio') {
                    $new_img->type = AUDIO;
                } elseif ($type == '_video') {
                    $new_img->type = VIDEO;
                } else {
                    $new_img->type = IMAGE;
                }
                if (empty($_POST['caption' . $type][$k])) {
                    $ext = explode(".", $newname);
                    $_POST['caption' . $type][$k] = $ext[0];
                }
                $new_img->title = stripslashes(trim($_POST['caption' . $type][$k]));
                $new_img->title = strip_tags($new_img->title);
                $new_img->file_perm = ANYONE;
                $new_img->excerpt = stripslashes(trim($_POST['caption' . $type][$k]));
                $new_img->excerpt = strip_tags($new_img->excerpt);
                if (empty($_POST['body' . $type][$k])) {
                    $new_img->body = '';
                    $new_img->body = strip_tags($new_img->body);
                } else {
                    $new_img->body = stripslashes(trim($_POST['body' . $type][$k]));
                    $new_img->body = strip_tags($new_img->body);
                }
                $new_img->allow_comments = 1;
                $new_img->parent_collection_id = $_POST['group_id'];
                $new_img->save();
                if (!empty($_POST['tags' . $type][$media_count_no])) {
                    $tag_array = Tag::split_tags($_POST['tags' . $type][$media_count_no]);
                    Tag::add_tags_to_content($new_img->content_id, $tag_array);
                }
            } else {
                throw new CNException(USER_NOT_FOUND, 'unable to upload file.');
            }
            if (!empty($msg)) {
                $uploaded = FALSE;
            } else {
                $uploaded = TRUE;
                if (isset($_REQUEST['gid'])) {
                    $mail_type = "group_media_uploaded";
                    $new_img->group_id = $_REQUEST['gid'];
                } else {
                    $mail_type = "media_uploaded";
                }
                PANotify::send($mail_type, PA::$network_info, PA::$login_user, $new_img);
            }
        } catch (CNException $e) {
            $msg = "{$e->message}";
            $error = TRUE;
        }
    }
    $array_of_error_message = array(@$error, @$msg, @$error_file, @$uploaded, 'collection_id' => $new_img->parent_collection_id, 'content_id' => $new_img->content_id);
    return $array_of_error_message;
}
 private function handleEdit($request_data)
 {
     $this->err = '';
     $data = $this->filter($request_data);
     // handle photo upload
     if (!empty($_FILES)) {
         foreach ($_FILES as $field_name => $file_info) {
             if (!empty($file_info['name'])) {
                 $uploadfile = PA::$upload_path . basename($_FILES[$field_name]['name']);
                 $myUploadobj = new FileUploader();
                 $file = $myUploadobj->upload_file(PA::$upload_path, $field_name, true, true, 'image');
                 if ($file == false) {
                     $msg = $myUploadobj->error;
                     $this->err .= sprintf(__('Please upload a valid Game Image in %s'), ucfirst($field_name)) . "<br/>";
                     continue;
                 } else {
                     Storage::link($file, array("role" => "game_image", "user" => PA::$login_user->user_id));
                     $data[$field_name] = $file;
                 }
             } else {
                 if (!empty($this->entity->attributes[$field_name])) {
                     $data[$field_name] = $this->entity->attributes[$field_name];
                 }
             }
         }
     }
     if (empty($data['name'])) {
         $this->err .= __("Please supply a name.") . "<br/>";
     }
     if (empty($this->err)) {
         // sync it
         TypedGroupEntity::sync($data);
     }
 }