Yii Framework Forum: Cfilevalidator Use For Not Uploaded File - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Cfilevalidator Use For Not Uploaded File Rate Topic: ****- 1 Votes

#1 User is offline   UASergey 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 24
  • Joined: 06-June 13

Posted 27 October 2013 - 07:00 PM

I have a lot of images. I should to valid them. But the images are on the local file system. How can I valid them without CUploadedFile::getInstance?

I tried to do this:


$_FILES['temp_path']['tmp_name'] = '/home/user/1.jpg';
$_FILES['temp_path']['name'] = '1.jpg';
$_FILES['temp_path']['type'] = 'image/jpeg';
$_FILES['temp_path']['size'] = '545458';
$_FILES['temp_path']['error'] = 0;

$model->attribute = CUploadedFile::getInstance($model, "temp_path");


But I have got an error Missing argument 2 for CActiveRecord::setAttribute().
0

#2 User is offline   Ankit Modi 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 873
  • Joined: 19-February 13
  • Location:India

Posted 28 October 2013 - 02:39 AM

Hi just add on model rule function and set scenario like

array('image_name','required','on'=>'create'),
 array('image_name', 'file', 'types' => 'jpg, jpeg, gif,  png','on'=>'create','minSize'=>559631,'tooLarge'=>'The file was  larger than 559631K. Please upload a smaller file.'),
array('image_name', 'file', 'allowEmpty' => TRUE,'types' => 'jpg, jpeg, gif, png','on'=>'update'),


I hope it's some help
Thanks,
Ankit Modi
Skype : amodi06
0

#3 User is offline   UASergey 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 24
  • Joined: 06-June 13

Posted 01 November 2013 - 06:05 PM

View PostMaggie Q(Ankit Modi), on 28 October 2013 - 02:39 AM, said:

Hi just add on model rule function and set scenario like

array('image_name','required','on'=>'create'),
 array('image_name', 'file', 'types' => 'jpg, jpeg, gif,  png','on'=>'create','minSize'=>559631,'tooLarge'=>'The file was  larger than 559631K. Please upload a smaller file.'),
array('image_name', 'file', 'allowEmpty' => TRUE,'types' => 'jpg, jpeg, gif, png','on'=>'update'),


I hope it's some help


Unfortunately it does not work. 2nd rule in example requires 'Temp Path cannot be blank.'
0

#4 User is offline   KonApaz 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,311
  • Joined: 21-February 11
  • Location:Greece

Posted 30 December 2013 - 05:53 PM

View PostUASergey, on 27 October 2013 - 07:00 PM, said:

I have a lot of images. I should to valid them. But the images are on the local file system. How can I valid them without CUploadedFile::getInstance?

I tried to do this:


$_FILES['temp_path']['tmp_name'] = '/home/user/1.jpg';
$_FILES['temp_path']['name'] = '1.jpg';
$_FILES['temp_path']['type'] = 'image/jpeg';
$_FILES['temp_path']['size'] = '545458';
$_FILES['temp_path']['error'] = 0;

$model->attribute = CUploadedFile::getInstance($model, "temp_path");


But I have got an error Missing argument 2 for CActiveRecord::setAttribute().



attribute invoke setAttribute function that has 2 arguments (name and value)
http://www.yiiframew...ttribute-detail

are you seek attributes instead attribute ?

Also CUploadedFile::getInstance returns a CUploadedFile object, so you can't pass masive attributes directly

What exactly are you trying to do?
Yii is the best php framework in the world!
find our demo Yii extension on www.webkit.gr
Is it post useful? please v++ ;)
0

Share this topic:


Page 1 of 1
  • 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