[Extension] Xupload
#261
Posted 04 November 2012 - 04:09 AM
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'
#262
Posted 04 November 2012 - 03:19 PM
storemalt, on 04 November 2012 - 04:09 AM, said:
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: 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
#263
Posted 04 November 2012 - 06:27 PM
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)
#264
Posted 05 November 2012 - 06:00 AM
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.
#265
Posted 05 November 2012 - 10:11 AM
- 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
#266
Posted 09 November 2012 - 02:24 AM
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)
-
xupload-workflow.zip (4.56K)
Number of downloads: 40
#267
Posted 11 November 2012 - 09:41 PM
#268
Posted 12 November 2012 - 08:30 AM
storemalt, on 11 November 2012 - 09:41 PM, 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.
- 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
#269
Posted 16 November 2012 - 05:19 AM
#270
Posted 16 November 2012 - 09:24 AM
izac, on 16 November 2012 - 05:19 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.
- 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
#271
Posted 16 November 2012 - 09:28 AM
Asgaroth, on 16 November 2012 - 09:24 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?
#272
Posted 16 November 2012 - 09:31 AM
izac, on 16 November 2012 - 09:28 AM, said:
I'm sorry, I'm not understanding, English is not may main language so you got to be more descriptive.
- 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
#273
Posted 17 November 2012 - 04:39 PM
#274
Posted 17 November 2012 - 04:51 PM
PhysX, on 17 November 2012 - 04:39 PM, said:
Not sure what to answer, at least the demo should be working. but without information there is nothing I can help you with.
- 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
#275
Posted 18 November 2012 - 02:33 AM
Asgaroth, on 12 November 2012 - 08:30 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..
#276
Posted 21 November 2012 - 05:20 AM
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?
#277
Posted 21 November 2012 - 08:10 AM
- 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
#278
Posted 21 November 2012 - 07:30 PM
storemalt, on 18 November 2012 - 02:33 AM, said:
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?
#279
Posted 22 November 2012 - 08:51 AM
storemalt, on 21 November 2012 - 07:30 PM, 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.
- 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