Yii Framework Forum: Upload - Verot - Yii Framework Forum

Jump to content

  • (2 Pages)
  • +
  • 1
  • 2
  • You cannot start a new topic
  • You cannot reply to this topic

Upload - Verot Rate Topic: -----

#1 User is offline   prchakal 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 95
  • Joined: 20-January 10

Posted 01 February 2010 - 02:30 AM

Hi,

This topic is for verot.net upload class with image handle.

Documentation:

// import the class
Yii::import('application.extensions.upload.Upload');

// receive file from post
$Upload = new Upload( (isset($_FILES['Filedata']) ? $_FILES['Filedata'] : null) );
$Upload->jpeg_quality  = 100;
$Upload->no_script     = false;
$Upload->image_resize  = true;
$Upload->image_x       = 700;
$Upload->image_y       = 500;
$Upload->image_ratio   = true;

// some vars
$newName  = date('YmdHis');
$destPath = Yii::app()->getBasePath().'/../images/gallery/';
$destName = '';

// verify if was uploaded
if ($Upload->uploaded) {
    $Upload->file_new_name_body = $newName;			
    $Upload->process($destPath);
	
	// if was processed
	if ($Upload->processed) {
            $destName = $Upload->file_dst_name;    
        
            // write image filename on table
            $photo = new Photo();
            $photo->gallery = $_POST['gallery_id'];
            $photo->image_normal = $destName;
            $photo->image_thumb  = 'thumb_' . $destName;
            $photo->save();
        
            // create the thumb  
            unset($Upload);			  
        
            $Upload = new Upload($destPath.$destName);
            $Upload->file_new_name_body   = 'thumb_' . $newName;
            $Upload->no_script            = false;
            $Upload->image_resize         = true;
            $Upload->image_x              = 120;
            $Upload->image_y              = 80;
            $Upload->image_ratio          = true;
            $Upload->process($destPath);
		  
	} else {
            echo($Upload->error)
	}
} else {
    echo('Select a file to send');
}


Some samples:

http://www.verot.net...oad_samples.htm
0

#2 User is offline   prchakal 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 95
  • Joined: 20-January 10

Posted 05 February 2010 - 07:43 PM

I make the support for EXTENSION DOWNLOAD command.

You can get with console command:
extension install upload

You can see how to use this command, here:
http://www.yiiframew...nent-extension/
0

#3 User is offline   joeysantiago 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 63
  • Joined: 01-April 10

Posted 15 April 2010 - 08:18 AM

hello,

this is great... i'd like to be able to use it too! :)

is it ok to use it with an activeFileField like this?

	<div class="row">
		<?php echo CHtml::activeLabelEx($model,'immagine'); ?>
		<?php echo CHtml::activeFileField($model,'immagine',array('size'=>60,'maxlength'=>320)); ?>
		<?php echo CHtml::error($model,'immagine'); ?>
	</div>


my Controller can't find the file; how should i use this line ?

$Upload = new Upload( (isset($_FILES['immagine']) ? $_FILES['immagine'] : null) );

$_FILES['immagine'] is always null! :(

thanks!
joey santiago

an Italian with Suomi inside.
0

#4 User is offline   bitshine 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 27
  • Joined: 11-May 09

Posted 12 July 2010 - 10:12 PM

View Postprchakal, on 01 February 2010 - 02:30 AM, said:


// write image filename on table
$photo = new Photo();
$photo->gallery = $_POST['gallery_id'];
$photo->image_normal = $destName;
$photo->image_thumb = 'thumb_' . $destName;
$photo->save();



where is the class Photo?
0

#5 User is offline   bitshine 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 27
  • Joined: 11-May 09

Posted 12 July 2010 - 10:18 PM

Sorry, I think it is a model. :lol:
0

#6 User is offline   prchakal 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 95
  • Joined: 20-January 10

Posted 12 July 2010 - 10:23 PM

View Postbitshine, on 12 July 2010 - 10:12 PM, said:

where is the class Photo?



Hi.

This is an example, that show how to store the filename on database.

And joeysantiago:

You have to create a form with enctype=multpart, like this:

<?php echo CHtml::form('','post',array('enctype'=>'multipart/form-data')); ?>
...
<input type="file" name="immagine" />
...
<?php echo CHtml::endForm(); ?>

0

#7 User is offline   abud 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 27
  • Joined: 01-February 09

Posted 10 September 2010 - 07:44 AM

thanks for this great ext class, it very help me


i want to ask, the upload is file success but i can't rezise the image????
0

#8 User is offline   Drewniacki 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 37
  • Joined: 19-July 10
  • Location:Gdańsk, Poland

Posted 23 September 2010 - 07:04 AM

Can I somehow GET properties of an uploaded file? Just reading properties $upload->image_x gives me some strange results.
0

#9 User is offline   Drewniacki 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 37
  • Joined: 19-July 10
  • Location:Gdańsk, Poland

Posted 23 September 2010 - 07:27 AM

I have found solution by myself. All the essentials are here: http://www.verot.net...ass.upload.html
0

#10 User is offline   Alarice Chan 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 12
  • Joined: 23-September 10

Posted 03 March 2011 - 03:49 AM

Hello. I'm testing this out on my WAMP(Windows Apache MySQL PHP) installation and I have GD2 enabled but it refuses to do anything but write the image in its original form. :o
0

#11 User is offline   kitune 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 121
  • Joined: 27-February 11

Posted 14 June 2011 - 09:14 AM

My code is not working I don't know why.....

I have this funcition in controller:

public function actionUploadImage($id)
	{	
		
		// import the class
		Yii::import('application.extensions.upload.Upload');
	
		echo "<pre>";
		print_r($_FILES['Filedata']);		
		echo "</pre>";

		// receive file from post
		$Upload = new Upload(isset($_FILES['Filedata']));
		
		// some vars
		$newName  = date('YmdHis');		
		$destPath = Yii::app()->request->baseUrl;			
		$destName = '';
		
		// verify if was uploaded
		if ($Upload->uploaded) {			
		    $Upload->file_new_name_body = $newName;                     
		    $Upload->process($destPath);
		        
		        // if was processed
		        if ($Upload->processed) {
		            $destName = $Upload->file_dst_name;    
		        
		            // write image filename on table
		            /*$photo = new Photo();
		            $photo->gallery = $_POST['gallery_id'];
		            $photo->image_normal = $destName;
		            $photo->image_thumb  = 'thumb_' . $destName;
		            $photo->save();*/
		        
		            // create the thumb  
		            unset($Upload);                       
		        
		            $Upload = new Upload($destPath.$destName);
		            $Upload->file_new_name_body   = 'thumb_' . $newName;
		            $Upload->no_script            = false;
		            $Upload->image_resize         = true;
		            $Upload->image_x              = 120;
		            $Upload->image_y              = 80;
		            $Upload->image_ratio          = true;
		            $Upload->process($destPath);
		                  
		        } else {
		            echo($Upload->error);
		        }
		} else {

		 	   
		 	   $this->render('uploadimage',array(
				'model'=>$this->loadModel($id),				
			));
		}
	}


And an input in the view file.

print_r($_FILES['Filedata']) works fine, it returns:

Array
(
    [name] => Nenúfares.jpg
    [type] => image/jpeg
    [tmp_name] => C:\WINDOWS\Temp\php53F0.tmp
    [error] => 0
    [size] => 83794
)


But $Upload->uploaded is not working....Help!
0

#12 User is offline   kitune 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 121
  • Joined: 27-February 11

Posted 14 June 2011 - 09:29 AM

Ok I forgot this:

$Upload = new Upload(isset($_FILES['Filedata']));


to

$Upload = new Upload($_FILES['Filedata']);

0

#13 User is offline   bonnie 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 62
  • Joined: 08-February 11

Posted 10 August 2011 - 03:27 PM

Hi, Guys I like this awesome class for image/file manipulation.
I have an auto listing webapp. I have everything working, but not images. So I have spent my time trying to get this class working in yii application following prchakal post. I have two models one for handling listing information and one for handling image information.
In may Listing model I have the relationship
<?php
class Listing extends CActiveRecord
{
/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
                         //Other relationship here …………………………….
                          'images' => array(self::HAS_MANY,'AutoListingImages','listing_id'),
		);
//Other methods here

//The method for image upload
            public function saveImage()
           {
     //import the class for image manipulation from the extension folder
     Yii::import('application.extensions.upload.Upload');

     //Receive file/image data from the post request
     $Upload = new Upload((isset($_FILES['images']) ? $_FILES['images'] : null) );
     $Upload->jpeg_quality = 100;
     $Upload->no_script    = false;
     $Upload->image_resize = true;
     $Upload->image_x      = 300;
     $Upload->image_y      = 250;
     $Upload->image_ratio  = true;

     //some vars
     $rand = rand(1000,9000);
     $newName = $rand;
     $image_path = Yii::app()->getBasePath().'/upload_images/listing_uploads/';
     $image_thumb_path = Yii::app()->getBasePath().'/upload_images/listing_uploads/thumbnails/';
     $destName = '';

     //Verify if was uloaded
     if($Upload->uploaded) {
         $Upload->file_new_name_body = $newName;
         $Upload->process($image_path);

         //if was processed
         if($Upload->processed) {
             $destName = $Upload->file_dst_name;
             $thumbDestName = 'thumb_'.$destName;
             //write image file on the database
             $image = new AutoListingImages();
             $image->image_path = $image_path/$destName;
             $image->image_thumb_path = $image_thumb_path/$thumbDestName;
             $image->listing_id = $_POST[listing_id];
             //$image->create_time = new CDbExpression('NOW()');
             //$image->author_id = $author_id;
             $image->save();

             //Create the thumb
             unset ($Upload);
             $xUpload = new Upload($image_thumb_path.$destName);
             $Upload->file_new_name_body = 'thumb_' . $newName;
             $Upload->no_script    = false;
             $Upload->image_resize = true;
             $Upload->image_x      = 85;
             $Upload->image_y      = 50;
             $Upload->image_ratio  = true;
             $Upload->process($image_thumb_path);
         }  else {
             echo ($Upload->error);
         }
     }  else {
         echo "Select an image to upload";
     }
   }



In my ListingImages model I have
<?php
class ListingImages extends CActiveRecord
{
/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('image_path, image_thumb_path', 'required'),
			array('main_image, listing_id', 'numerical', 'integerOnly'=>true),
			array('image_path, image_thumb_path', 'length', 'max'=>255),

			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('listing_id', 'safe', 'on'=>'search'),
		);
	}
/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
                         //Other relationship here …………………………….
                          // NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
		'listing' => array(self::BELONGS_TO, 'Listing', 'listing_id'),
		);		);
	}



Here is my controller which is the controller for my model Listing
<?php
class AutoListingsController extends Controller
{
/**
	 * Creates a new model.
	 * If creation is successful, the browser will be redirected to the 'view' page.
	 */
	public function actionCreate()
	{
            		$model = new Listing;

		// Uncomment the following line if AJAX validation is needed
		$this->performAjaxValidation($model);

		if(isset($_POST['Listing']))
		{
			$model->attributes=$_POST['Listing'];
                        //This is how you capture those uploaded images.
                        //$model->images = CUploadedFile::getInstance($model, 'images');
			if($model->save())
                        {
                        if($model->images !== null)
                        $model->saveImage();

			$this->redirect(array('view','id'=>$model->id));
                        }
		}
		$this->render('create',array(
	        'model'=>$model,
		));
	}
}



And here is my partial _form.
<div class="form">

<?php $form=$this->beginWidget('CActiveForm',array(
	'id'=>'listing-form',
        'enableClientValidation' => true,
	'enableAjaxValidation'=>true,
        'htmlOptions'=>array('enctype'=>'multipart/form-data'),
)); ?>
<p class="note">Fields with <span class="required">*</span> are required.</p>

<div class="row">
    <?php echo $form->labelEx($model,'ad_title'); ?>
    <?php echo $form->textField($model,'ad_title',array('size'=>30,'maxlength'=>60)); ?>Example. New Toyota corolla in Kayole
    <?php echo $form->error($model,'ad_title'); ?>
</div>
<div class="row">
    <?php echo $form->labelEx($model,'images'); ?>
    <?php //echo CHtml::activeFileField($model, "[0]images");?>
    <br/>
    <?php //echo CHtml::activeFileField($model, "[1]images");?>
    <br/>
    <?php echo CHtml::activeFileField($model, "images");?>
</div>
<div class="row buttons">
<?php echo CHtml::submitButton($model->isNewRecord ? 'Add Listing' : 'Save'); ?>
</div>
<?php $this->endWidget(); ?>

</div><!-- form -->



With this arrangement of models, controllers and the form My images are not uploading and no errors showing up. I don’t know where the issues is. Also how can I support multiple image upload. The only information I need for image table is image_path, image_thumb_path, author_id, listing_id and create_time. Please help.
0

#14 User is offline   prchakal 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 95
  • Joined: 20-January 10

Posted 10 August 2011 - 04:10 PM

Hi,

You set see in apache error log.

You can verify if your target path has permission (777) to write.

Single upload or multiple upload doesn't depends of your server code, you only need use a client jquery plugin (for example) to make the interface for multiple upload support. Your server code is the same for both.
0

#15 User is offline   bonnie 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 62
  • Joined: 08-February 11

Posted 10 August 2011 - 09:55 PM

View Postprchakal, on 10 August 2011 - 04:10 PM, said:

Hi,

You set see in apache error log.

You can verify if your target path has permission (777) to write.

Single upload or multiple upload doesn't depends of your server code, you only need use a client jquery plugin (for example) to make the interface for multiple upload support. Your server code is the same for both.


I got it working I had to change
<div class="row">
    <?php echo $form->labelEx($model,'images'); ?>
    <?php //echo CHtml::activeFileField($model, "[0]images");?>
    <br/>
    <?php //echo CHtml::activeFileField($model, "[1]images");?>
    <br/>
    <?php echo CHtml::activeFileField($model, "images");?>
</div>
<?php echo CHtml::form('','post',array('enctype'=>'multipart/form-data')); ?>
...
<input type="file" name="images" />
...
<?php echo CHtml::endForm(); ?>
But just used CMultiFileUpload for multiple file upload
[code]
<?php $this->widget('CMultiFileUpload', array(
                //'model'=>$model,
                //'attribute' => 'images',
                'name' => 'images',//if not within a model
                'accept' => 'jpeg|jpg|gif|png', // useful for verifying files
                'duplicate' => 'Duplicate file!', // useful, i think
                'denied' => 'Invalid file type', // useful, i think
                'max' => '3',
                'remove' => 'delete',
                'selected' => 'You selected. $file',
            )); ?>

[/code]
To
0

#16 User is offline   fgpsmith 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 7
  • Joined: 20-October 11

Posted 08 January 2012 - 03:10 PM

Are there any plans to update this extension to use the latest version of the Verot library (0.31)? That version has added the ability to automatically resize watermarks to fit the resulting picture.
0

#17 User is offline   Dyego Nery 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 105
  • Joined: 26-August 11

Posted 27 March 2012 - 09:55 PM

Just a doubt that i got. Do the extension accept more than 1 file in the $_FILES?

I want to send a lot of images, at the same time. Is this possible?
http://www.emuitocarro.com.br - Classificado Online de Veículos


http://www.yiibrasil.com.br - Blog com dicas e tutoriais sobre o Yii Framework.
0

#18 User is offline   bonnie 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 62
  • Joined: 08-February 11

Posted 19 May 2012 - 05:27 PM

View PostDyego Nery, on 27 March 2012 - 09:55 PM, said:

Just a doubt that i got. Do the extension accept more than 1 file in the $_FILES?

I want to send a lot of images, at the same time. Is this possible?

It does I use it to upload multiple images in my app. I have a product table and each product can have multiple images.
0

#19 User is offline   biazouk 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 1
  • Joined: 08-July 12
  • Location:Rio de Janeiro - Brasil

Posted 08 July 2012 - 01:06 PM

Hi, I also had the same problem: "I can send it, but I can't resize the image".

I solved this way:

...
$image= '';
if ($model->photo=CUploadedFile::getInstance($model,'photo')){
  $image['name'] = $model->photo->name;
  $image['tmp_name'] = $model->photo->tempName;
  $image['size'] = $model->photo->size;
  $image['type'] = $model->photo->type;
  $image['error'] = $model->photo->error;
}


Yii::import('application.extensions.upload.Upload');

$Upload = new Upload($image);
...


In Controller, for example:

public function actionUpdate()
	{
		$model=$this->loadModel();

		// Uncomment the following line if AJAX validation is needed
		// $this->performAjaxValidation($model);

		if(isset($_POST['Event']))
		{
			$model->attributes=$_POST['Event'];
			
			$image= '';
			if ($model->photo=CUploadedFile::getInstance($model,'photo')){
				//print_r($model->photo).' <br> ';
				//echo($model->photo->tempName).' <br> ';
				$image['name'] = $model->photo->name;
				$image['tmp_name'] = $model->photo->tempName;
				$image['size'] = $model->photo->size;
				$image['type'] = $model->photo->type;
				$image['error'] = $model->photo->error;
			}
			
			if($model->save()){
				// import the class
				Yii::import('application.extensions.upload.Upload');
		
				// receive file from post
				$Upload = new Upload($image, 'pt_BR');
				$Upload->file_overwrite = true; 
				$Upload->image_convert  = 'jpg'; 
				$Upload->jpeg_quality   = 100;
				$Upload->no_script      = false;
				$Upload->image_resize   = true;
				$Upload->image_x        = 300;
				$Upload->image_y        = 300;
				$Upload->image_ratio_crop  = true; 
				//$Upload->image_ratio    = true; 
				//$Upload->image_ratio_fill = true; 
				//$Upload->image_background_color = '#000000';
		
				$Upload->dir_chmod      = 0777;
		
				// some vars
				$newName  = 'f'.$model->id;
				$destPath = Yii::app()->getBasePath().'/../images/events/';
		
				// verify if was uploaded
				if ($Upload->uploaded) {
				    $Upload->file_new_name_body = $newName;                     
				    $Upload->process($destPath);
				
				    // if was processed
				    if ($Upload->processed) {
					$result = 'ok';
					//$result = $Upload->log;
					unset($Upload);
				    } else {
					$result = $Upload->error;
				    }
				} 
				else {
				    $result = 'Select a image to send.';
				}

				if ($result == 'ok'){
				    $this->redirect(array('view','id'=>$model->id));
				} else {
				    echo 'Image: '.$result.'<br>';	
				}
			}
		}

		$this->render('update',array(
			'model'=>$model,
		));
	}


View Postabud, on 10 September 2010 - 07:44 AM, said:

thanks for this great ext class, it very help me


i want to ask, the upload is file success but i can't rezise the image????

0

#20 User is offline   kitune 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 121
  • Joined: 27-February 11

Posted 15 October 2013 - 08:15 AM

Hi! Hoy can I update to the latest version of class.upload http://www.verot.net...d_download.htm?

I have to replace upload.php and it's done?
0

Share this topic:


  • (2 Pages)
  • +
  • 1
  • 2
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users