Yii Framework Forum: [Extension] Xupload - Yii Framework Forum

Jump to content

  • (20 Pages)
  • +
  • « First
  • 12
  • 13
  • 14
  • 15
  • 16
  • Last »
  • You cannot start a new topic
  • You cannot reply to this topic

[Extension] Xupload Rate Topic: ***** 1 Votes

#261 User is offline   storemalt 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 32
  • Joined: 22-April 11

Posted 04 November 2012 - 04:09 AM

Hi guys i really need help..

im having a hard time to set acceptFileTypes on the UI version, using this extension.. how do you guys set restrictions for file types?

<?php
$this->widget( 'xupload.XUpload', array(
'url' => url('/test/upload'),
'model' => $image,
'htmlOptions' => array('id'=>'image-form'),
'attribute' => 'name',
'multiple' => true,
'options' => array(
'acceptFileTypes'=>'/\.(png)|(jpg)|(gif)|(jpeg)$/i'
),
));
?>

this doesnt work though, i get Object /\.(png)|(jpg)|(gif)|(jpeg)$/i has no method 'test'
0

#262 User is offline   Asgaroth 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 371
  • Joined: 17-July 09
  • Location:Bogota, Colombia

Posted 04 November 2012 - 03:19 PM

View Poststoremalt, on 04 November 2012 - 04:09 AM, said:

Hi guys i really need help..

im having a hard time to set acceptFileTypes on the UI version, using this extension.. how do you guys set restrictions for file types?

<?php
$this->widget( 'xupload.XUpload', array(
'url' => url('/test/upload'),
'model' => $image,
'htmlOptions' => array('id'=>'image-form'),
'attribute' => 'name',
'multiple' => true,
'options' => array(
'acceptFileTypes'=>'/\.(png)|(jpg)|(gif)|(jpeg)$/i'
),
));
?>

this doesnt work though, i get Object /\.(png)|(jpg)|(gif)|(jpeg)$/i has no method 'test'


http://www.yiiframew...post__p__155944
- Extension: Dynamic DataProvider Behavior
- Extension: XUpload - jQuery File Upload Extension
- Extension: PhpQuickProfiler - A Web Log Router that will help you profile your application
- Extension: XDateView - A Date grouped Grid View
- Extension: Foundation - An easy to use, powerful, and flexible framework for building prototypes and production code on any kind of device.



- Wiki: How to generate Yii like Documentation
- Wiki: How to re enable logging during unit testing
0

#263 User is offline   storemalt 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 32
  • Joined: 22-April 11

Posted 04 November 2012 - 06:27 PM

thanks asgaroth it works..

btw.. is there a way we can view the thumbnails in galleries instead of downloading? and the link on the right side is still download?

or something like bootstrap-image-gallery? (if we can also include this would definitely be super wonderful)
0

#264 User is offline   Efrain Melo 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 1
  • Joined: 05-November 12

Posted 05 November 2012 - 06:00 AM

Hi Asgaroth,

in this moment, i am working in a develop uploading images and it works perfectly. however, i want to load many images, then leave the page ans the return to the page to see all that are loaded.

it is my controller
class UploadController extends Controller {
	
	public function actionIndex() {
		Yii::import ( "xupload.models.XUploadForm" );
		$model = new XUploadForm ();
		
		$id = $_GET ["idProducto"];
		
		$producto = Producto::model ()->findByPk ( $id );
		
		$exclude_list = array(".", "..");
		
		$path = realpath ( Yii::app ()->getBasePath () . "/../images/productos/" ) . "\\" . $id . "\\";
		$publicPath = Yii::app ()->getBaseUrl () . "/images/productos/" . $id . "/";
		
		$directories = array_diff(scandir($path), $exclude_list);
		$image = 0;
		foreach($directories as $filename) {
			
			$image_info = @getimagesize($path.$filename);
			
			$imagesize = filesize($path . $filename);
			
			$userImages [] = array ("path" => $path . $filename, //the same file or a thumb version that you generated
					"thumb" => $path.'thumbs/'. $filename,
					"filename" => $filename,
					'size' => $imagesize,
					'mime' => $image_info['mime'],
					'name' => "imagen ".$image );
			
			$data[] = array (
				   "name" => "imagen ".$image, 
				   "type" => $image_info['mime'], 
				   "size" => $imagesize, 
				   "url" => $publicPath . $filename, 
				   "thumbnail_url" => $publicPath . "thumbs/$filename", 
				   "delete_url" => $this->createUrl ( "upload", array ("_method" => "delete", "file" => $filename, "idProducto"=>$IdProducto ) ), 
				   "delete_type" => "POST" );
			
			$image++;
			
		}
		
		$model->filename = $path . $filename;
		$model->file = CUploadedFile::getInstance ( $model, 'file' );
		
		Yii::app ()->user->setState ( 'images', $userImages );
		
		$this->render ( 'index', array ('model' => $model, 'Producto' => $producto, 'DataImg' => json_encode($data) ) );
	}
	
	public function actions() {
		return array ('upload' => array ('class' => 'xupload.actions.XUploadAction', 
				'path' => Yii::app ()->getBasePath () . "/../uploads", 
				'publicPath' => Yii::app ()->getBaseUrl () . "/uploads", 
				'subfolderVar' => "parent_id" 
			) 
		);
	}
	// Uncomment the following methods and override them if needed
	/*
	public function filters()
	{
		// return the filter configuration for this controller, e.g.:
		return array(
			'inlineFilterName',
			array(
				'class'=>'path.to.FilterClass',
				'propertyName'=>'propertyValue',
			),
		);
	}
	*/
	public function actionUpload() {
		Yii::import ( "xupload.models.XUploadForm" );
			
		if(isset( $_GET ['idProducto'])){
			$IdProducto = $_GET ['idProducto'];
			//Here we define the paths where the files will be stored temporarily
			$path = realpath ( Yii::app ()->getBasePath () . "/../images/productos/" ) . "\\" . $IdProducto . "\\";
			$publicPath = Yii::app ()->getBaseUrl () . "/images/productos/" . $IdProducto . "/";
		}
		if (isset ( $IdProducto ) && !isset($_GET ["_method"])) {
			
			//This is for IE which doens't handle 'Content-type: application/json' correctly
			header ( 'Vary: Accept' );
			if (isset ( $_SERVER ['HTTP_ACCEPT'] ) && (strpos ( $_SERVER ['HTTP_ACCEPT'], 'application/json' ) !== false)) {
				header ( 'Content-type: application/json' );
			} else {
				header ( 'Content-type: text/plain' );
			}
			
			$model = new XUploadForm ();
			
			$model->file = CUploadedFile::getInstance ( $model, 'file' );
			//We check that the file was successfully uploaded
			
			if ($model->file !== null) {
				//Grab some data
				$model->mime_type = $model->file->getType ();
				$model->size = $model->file->getSize ();
				$model->name = $model->file->getName ();
				//(optional) Generate a random name for our file
				$filename = md5 ( Yii::app ()->user->id . microtime () . $model->name );
				$filename .= "." . $model->file->getExtensionName ();
				if ($model->validate ()) {
					
					if (! is_dir ( $path )) {
						mkdir ( $path, 0777, true );
						chmod ( $path, 0777 );
						//throw new CHttpException(500, "{$this->path} does not exists.");
					}
					
					if (! is_dir ( $path."/thumbs/" )) {
						mkdir ( $path."/thumbs/", 0777, true );
						chmod ( $path, 0777 );
					}
					
					//Move our file to our temporary dir
					$model->file->saveAs ( $path . $filename );
					chmod ( $path . $filename, 0777 );
					//here you can also generate the image versions you need 
					//using something like PHPThumb
					
					Yii::import('application.extensions.image.Image');
					$image = new Image($path.$filename);
					
	                $image->resize(80, 80)->quality(75);
	                $image->save($path."/thumbs/".$filename);
					
					//Now we need to save this path to the user's session
					if (Yii::app ()->user->hasState ( 'images' )) {
						$userImages = Yii::app ()->user->getState ( 'images' );
					} else {
						$userImages = array ();
					}
					$userImages [] = array ("path" => $path . $filename, //the same file or a thumb version that you generated
					"thumb" => $path . $filename, 
					"filename" => $filename, 
					'size' => $model->size, 
					'mime' => $model->mime_type, 
					'name' => $model->name );
					Yii::app ()->user->setState ( 'images', $userImages );
					
					//Now we need to tell our widget that the upload was succesfull
					//We do so, using the json structure defined in
					echo json_encode ( array (array ("name" => $model->name, "type" => $model->mime_type, "size" => $model->size, "url" => $publicPath . $filename, "thumbnail_url" => $publicPath . "thumbs/$filename", "delete_url" => $this->createUrl ( "upload", array ("_method" => "delete", "file" => $filename, "idProducto"=>$IdProducto ) ), "delete_type" => "POST" ) ) );
				} else {
					//If the upload failed for some reason we log some data and let the widget know
					echo json_encode ( array (array ("error" => $model->getErrors ( 'file' ) ) ) );
					Yii::log ( "XUploadAction: " . CVarDumper::dumpAsString ( $model->getErrors () ), CLogger::LEVEL_ERROR, "xupload.actions.XUploadAction" );
				}
			} else {
				throw new CHttpException ( 500, "Could not upload file" );
			}
		} //Here we check if we are deleting and uploaded file
		else if (isset ( $_GET ["_method"] )) {
			if ($_GET ["_method"] == "delete") {
				if ($_GET ["file"] [0] !== '.') {
					$file = $path . $_GET ["file"];
					if (is_file ( $file )) {
						unlink ( $file );
						unlink ($path."/thumbs/".$file);
					}
				}
				echo json_encode ( true );
			}
		} else {
			throw new CHttpException ( 500, "Ingrese los datos del producto" );
		}
	}
}


this is my view

<?php
/* @var $this UploadController */

$this->breadcrumbs=array(
	'Upload',
);
?>

<div class="form">

<?php $form=$this->beginWidget('CActiveForm', array(
	'id'=>'upload-index',
	'enableAjaxValidation'=>false,
	//This is very important when uploading files
    'htmlOptions' => array('enctype' => 'multipart/form-data'),
)); ?>
<h1><?php echo $this->id . '/' . $this->action->id; ?></h1>

<?php $this->widget('zii.widgets.CDetailView', array(
	'data'=>$Producto,
	'attributes'=>array(
		'nombre',
		'descripcion',
		array(
			'name'=>'categoria',
			'value' =>CHtml::encode($Producto->categoria->nombre),
		),
		array(
			'name'=>'proveedor',
			'value' =>CHtml::encode($Producto->proveedor->nombre),
		),
		array(
			'name'=>'productoEstado',
			'value'=>CHtml::encode($Producto->productoEstado->nombre),
		)
	),
)); ?>
	
	<div class="row">
		<?php echo $form->labelEx($model,'photos'); ?>
            <?php 
            $this->widget( 'xupload.XUpload', array(
                'url' => Yii::app( )->createUrl( "/Upload/upload", array("idProducto"=>$Producto->id)),
                //our XUploadForm
                'model' => $model,
                //We set this for the widget to be able to target our own form
                'htmlOptions' => array('id'=>'upload-index',
						'formData'=>$DataImg				
				),
				'options' => array(//Additional javascript options
	               'completed'=>'js:function(){location.reload(true);}',
                ),
                'attribute' => 'file',
                'multiple' => true,
            	'heigth' => 400,
            	'width' => 400, 
			    //Note that we are using a custom view for our widget
                //Thats becase the default widget includes the 'form' 
                //which we don't want here
                )    
            );
            ?>
    </div>

<?php $this->endWidget(); ?>
</div>


thank you very much.

greetings from Colombia.
0

#265 User is offline   Asgaroth 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 371
  • Joined: 17-July 09
  • Location:Bogota, Colombia

Posted 05 November 2012 - 10:11 AM

I didn't quite understand your question, if what you want its to preload a list of images in the widget, please search this thread, people has solved this before.
- Extension: Dynamic DataProvider Behavior
- Extension: XUpload - jQuery File Upload Extension
- Extension: PhpQuickProfiler - A Web Log Router that will help you profile your application
- Extension: XDateView - A Date grouped Grid View
- Extension: Foundation - An easy to use, powerful, and flexible framework for building prototypes and production code on any kind of device.



- Wiki: How to generate Yii like Documentation
- Wiki: How to re enable logging during unit testing
0

#266 User is offline   innocube 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 4
  • Joined: 19-February 12

Posted 09 November 2012 - 02:24 AM

Hi Asgaroth,
First thank you for your update on xupload-workflow upon my request to add files names. However with that extra help, I am still having some issues.

This is what I have on my test server on top of working xupload demo applied (working):

What I want to do is to have a demo site on top of your xupload extension. Any help please? Thank you!

P.S. Since I was not allowed include any link in my post, I attached a zip file containing all the files for XUpload-Workflow Demo.

Attached File(s)


0

#267 User is offline   storemalt 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 32
  • Joined: 22-April 11

Posted 11 November 2012 - 09:41 PM

is there a way we can view the thumbnails in galleries instead of downloading? and the link on the right side is still download?
0

#268 User is offline   Asgaroth 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 371
  • Joined: 17-July 09
  • Location:Bogota, Colombia

Posted 12 November 2012 - 08:30 AM

View Poststoremalt, on 11 November 2012 - 09:41 PM, said:

is there a way we can view the thumbnails in galleries instead of downloading? and the link on the right side is still download?


This is out of the scope of the extension, however, if many people request it, it may be added. but in any case, if you already have a gallery in javascript, or a plugin that does it, it shouldn't be hard to plug it in. generally for the gallery plugins to work, you just need to add a class to the images, you can do that easily by overriding the XUpload upload template.
- Extension: Dynamic DataProvider Behavior
- Extension: XUpload - jQuery File Upload Extension
- Extension: PhpQuickProfiler - A Web Log Router that will help you profile your application
- Extension: XDateView - A Date grouped Grid View
- Extension: Foundation - An easy to use, powerful, and flexible framework for building prototypes and production code on any kind of device.



- Wiki: How to generate Yii like Documentation
- Wiki: How to re enable logging during unit testing
0

#269 User is offline   izac 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 9
  • Joined: 16-November 12

Posted 16 November 2012 - 05:19 AM

Hi I'm just starting to understand the Yii and ran into a problem installing xupload, did everything by the manual but do not call widget is loaded CSS and Js attached image rghost.ru/41600562/image.png
0

#270 User is offline   Asgaroth 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 371
  • Joined: 17-July 09
  • Location:Bogota, Colombia

Posted 16 November 2012 - 09:24 AM

View Postizac, on 16 November 2012 - 05:19 AM, said:

Hi I'm just starting to understand the Yii and ran into a problem installing xupload, did everything by the manual but do not call widget is loaded CSS and Js attached image rghost.ru/41600562/image.png


The styling is not part of the extension itself, the demo uses twitter bootstap, its a matter of adding bootstrap to your app. or you can add your own styles.
- Extension: Dynamic DataProvider Behavior
- Extension: XUpload - jQuery File Upload Extension
- Extension: PhpQuickProfiler - A Web Log Router that will help you profile your application
- Extension: XDateView - A Date grouped Grid View
- Extension: Foundation - An easy to use, powerful, and flexible framework for building prototypes and production code on any kind of device.



- Wiki: How to generate Yii like Documentation
- Wiki: How to re enable logging during unit testing
0

#271 User is offline   izac 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 9
  • Joined: 16-November 12

Posted 16 November 2012 - 09:28 AM

View PostAsgaroth, on 16 November 2012 - 09:24 AM, said:

The styling is not part of the extension itself, the demo uses twitter bootstap, its a matter of adding bootstrap to your app. or you can add your own styles.

Yes, but it also does not upload the files, I thought Chthon running after all the made-to guides http://www.yiiframew...ension/xupload/ from this srainy and can use return? or something to build upon their own hands?
0

#272 User is offline   Asgaroth 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 371
  • Joined: 17-July 09
  • Location:Bogota, Colombia

Posted 16 November 2012 - 09:31 AM

View Postizac, on 16 November 2012 - 09:28 AM, said:

Yes, but it also does not upload the files, I thought Chthon running after all the made-to guides http://www.yiiframew...ension/xupload/ from this srainy and can use return? or something to build upon their own hands?


I'm sorry, I'm not understanding, English is not may main language so you got to be more descriptive.
- Extension: Dynamic DataProvider Behavior
- Extension: XUpload - jQuery File Upload Extension
- Extension: PhpQuickProfiler - A Web Log Router that will help you profile your application
- Extension: XDateView - A Date grouped Grid View
- Extension: Foundation - An easy to use, powerful, and flexible framework for building prototypes and production code on any kind of device.



- Wiki: How to generate Yii like Documentation
- Wiki: How to re enable logging during unit testing
0

#273 User is offline   PhysX 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 2
  • Joined: 29-June 12

Posted 17 November 2012 - 04:39 PM

Hey, I'm having trouble getting the upload files queue to even populate. After trying to solve this for a while, I decided to try to run the demo, and I have the same problem there. I'm not sure what else I would need to do, I am using the latest version of Yii, there are no javascript errors or anything, I tried multiple browsers, the online demo works great. I click "Add File" and no matter what I choose, nothing happens in the GUI. Any ideas? Thanks!
0

#274 User is offline   Asgaroth 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 371
  • Joined: 17-July 09
  • Location:Bogota, Colombia

Posted 17 November 2012 - 04:51 PM

View PostPhysX, on 17 November 2012 - 04:39 PM, said:

Hey, I'm having trouble getting the upload files queue to even populate. After trying to solve this for a while, I decided to try to run the demo, and I have the same problem there. I'm not sure what else I would need to do, I am using the latest version of Yii, there are no javascript errors or anything, I tried multiple browsers, the online demo works great. I click "Add File" and no matter what I choose, nothing happens in the GUI. Any ideas? Thanks!


Not sure what to answer, at least the demo should be working. but without information there is nothing I can help you with.
- Extension: Dynamic DataProvider Behavior
- Extension: XUpload - jQuery File Upload Extension
- Extension: PhpQuickProfiler - A Web Log Router that will help you profile your application
- Extension: XDateView - A Date grouped Grid View
- Extension: Foundation - An easy to use, powerful, and flexible framework for building prototypes and production code on any kind of device.



- Wiki: How to generate Yii like Documentation
- Wiki: How to re enable logging during unit testing
0

#275 User is offline   storemalt 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 32
  • Joined: 22-April 11

Posted 18 November 2012 - 02:33 AM

View PostAsgaroth, on 12 November 2012 - 08:30 AM, said:

This is out of the scope of the extension, however, if many people request it, it may be added. but in any case, if you already have a gallery in javascript, or a plugin that does it, it shouldn't be hard to plug it in. generally for the gallery plugins to work, you just need to add a class to the images, you can do that easily by overriding the XUpload upload template.


Thanks asgaroth, great help and support..

Next Question:
"set form data on page load"

So ive already uploaded files and these files are automatically viewed using js_encode of the file properties and xupload immediately shows them on template, but how will i have the same view/result when i visit again the page next time (no uploads done yet)?

i tried doing an echo js_encode of the same properties in the controller, but instead it just printed out the data and was not read by the xupload, unlike what happens right after uploading files..

am i missing something? ive been reading, havent found any answers yet..
0

#276 User is offline   renathy 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 82
  • Joined: 05-July 11

Posted 21 November 2012 - 05:20 AM

I am working on an existing project.
Currently XUpload displays "Delete" possibility to uploaded files.
How can I remove it from there? I understand that there is some template, but mayby there is some config option to disable delete?
0

#277 User is offline   Asgaroth 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 371
  • Joined: 17-July 09
  • Location:Bogota, Colombia

Posted 21 November 2012 - 08:10 AM

there is an option to specify your own template, the default template does not have configuration options
- Extension: Dynamic DataProvider Behavior
- Extension: XUpload - jQuery File Upload Extension
- Extension: PhpQuickProfiler - A Web Log Router that will help you profile your application
- Extension: XDateView - A Date grouped Grid View
- Extension: Foundation - An easy to use, powerful, and flexible framework for building prototypes and production code on any kind of device.



- Wiki: How to generate Yii like Documentation
- Wiki: How to re enable logging during unit testing
0

#278 User is offline   storemalt 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 32
  • Joined: 22-April 11

Posted 21 November 2012 - 07:30 PM

View Poststoremalt, on 18 November 2012 - 02:33 AM, said:

Thanks asgaroth, great help and support..

Next Question:
"set form data on page load"

So ive already uploaded files and these files are automatically viewed using js_encode of the file properties and xupload immediately shows them on template, but how will i have the same view/result when i visit again the page next time (no uploads done yet)?

i tried doing an echo js_encode of the same properties in the controller, but instead it just printed out the data and was not read by the xupload, unlike what happens right after uploading files..

am i missing something? ive been reading, havent found any answers yet..


is this not possible?
0

#279 User is offline   Asgaroth 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 371
  • Joined: 17-July 09
  • Location:Bogota, Colombia

Posted 22 November 2012 - 08:51 AM

View Poststoremalt, on 21 November 2012 - 07:30 PM, said:

is this not possible?


I haven't done it myself, so I can't help you. but I've heard of other people doing this already. so to your question, yes - its possible.
- Extension: Dynamic DataProvider Behavior
- Extension: XUpload - jQuery File Upload Extension
- Extension: PhpQuickProfiler - A Web Log Router that will help you profile your application
- Extension: XDateView - A Date grouped Grid View
- Extension: Foundation - An easy to use, powerful, and flexible framework for building prototypes and production code on any kind of device.



- Wiki: How to generate Yii like Documentation
- Wiki: How to re enable logging during unit testing
0

#280 User is offline   storemalt 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 32
  • Joined: 22-April 11

Posted 23 November 2012 - 07:32 PM

View PostAsgaroth, on 22 November 2012 - 08:51 AM, said:

I haven't done it myself, so I can't help you. but I've heard of other people doing this already. so to your question, yes - its possible.


thank you :)
0

Share this topic:


  • (20 Pages)
  • +
  • « First
  • 12
  • 13
  • 14
  • 15
  • 16
  • Last »
  • You cannot start a new topic
  • You cannot reply to this topic

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