Adrianna
(Rhea Uplb)
May 7, 2014, 12:57am
1
I followed the step by step instruction given by this link My link.
It worked out just fine, but it only save file into database and not in the ‘directory’ I included.
This is my controller:
if(isset($_POST['PurchaseRequest']))
{
$model->attributes=$_POST['PurchaseRequest'];
$model->purchase_document = CUploadedFile::getInstance($model, 'purchase_document');
$model->class_name = $options->getCategoryatIndex($model->class_name);
if($model->save()){
$model->purchase_document->saveAs('.\files\pr');
$this->redirect(array('view','id'=>$model->id));
}
}
Note that i changed the (‘files/pr’) to (’.\files\pr’) for it to work because i get an error if I used the first one. I would really appreciate if someone can help me with this. Thank you.
jdgz
(Jose Daniel Galvan)
May 7, 2014, 1:39am
2
adrianna:
I followed the step by step instruction given by this link My link.
It worked out just fine, but it only save file into database and not in the ‘directory’ I included.
This is my controller:
if(isset($_POST['PurchaseRequest']))
{
$model->attributes=$_POST['PurchaseRequest'];
$model->purchase_document = CUploadedFile::getInstance($model, 'purchase_document');
$model->class_name = $options->getCategoryatIndex($model->class_name);
if($model->save()){
$model->purchase_document->saveAs('.\files\pr');
$this->redirect(array('view','id'=>$model->id));
}
}
Note that i changed the (‘files/pr’) to (’.\files\pr’) for it to work because i get an error if I used the first one. I would really appreciate if someone can help me with this. Thank you.
Did you change the access permissions (chmod 777) to the folder created?
Adrianna
(Rhea Uplb)
May 7, 2014, 1:51am
3
Yes. and still it does’nt work. :’(
jdgz
(Jose Daniel Galvan)
May 7, 2014, 2:07am
4
I think the problem is with the path, try with [dirname(FILE ).’/../path/to/file’]
Can you share the path of your folder created?
Adrianna
(Rhea Uplb)
May 7, 2014, 2:11am
5
I think the problem is with the path, try with [dirname(FILE ).’/../path/to/file’]
Can you share the path of your folder created?
this is the path of the folder I created /var/www/MyWebApp/files
jdgz
(Jose Daniel Galvan)
May 7, 2014, 2:30am
6
If so, then the path should be something like ‘/files’
Try with the following:
$model->purchase_document->setPath('/files');
$model->purchase_document->saveAs();
Adrianna
(Rhea Uplb)
May 7, 2014, 2:48am
7
If so, then the path should be something like ‘/files’
Try with the following:
$model->purchase_document->setPath('/files');
$model->purchase_document->saveAs();
but it says ‘CUploadedFile and its behaviors do not have a method or closure named “setPath”.’
ahmed201
(Rifajas)
May 7, 2014, 3:01am
8
you are just instructing to save on your path like this
$model -> purchase_document -> saveAs( '.\files\pr' );
append file name like this
$model -> purchase_document -> saveAs( '.\files\pr\foo.bar');
adrianna:
I followed the step by step instruction given by this link My link.
It worked out just fine, but it only save file into database and not in the ‘directory’ I included.
This is my controller:
if(isset($_POST['PurchaseRequest']))
{
$model->attributes=$_POST['PurchaseRequest'];
$model->purchase_document = CUploadedFile::getInstance($model, 'purchase_document');
$model->class_name = $options->getCategoryatIndex($model->class_name);
if($model->save()){
$model->purchase_document->saveAs('.\files\pr');
$this->redirect(array('view','id'=>$model->id));
}
}
Note that i changed the (‘files/pr’) to (’.\files\pr’) for it to work because i get an error if I used the first one. I would really appreciate if someone can help me with this. Thank you.
jdgz
(Jose Daniel Galvan)
May 7, 2014, 3:05am
9
$model->purchase_document->saveAs('/files');
Adrianna
(Rhea Uplb)
May 7, 2014, 3:12am
10
you are just instructing to save on your path like this
$model -> purchase_document -> saveAs( '.\files\pr' );
append file name like this
$model -> purchase_document -> saveAs( '.\files\pr\foo.bar');
It works, but still only saves the file to database and not on the directory I set.
Adrianna
(Rhea Uplb)
May 7, 2014, 3:13am
11
I tried that code several times, but still don’t work for me
Adrianna
(Rhea Uplb)
May 7, 2014, 3:34am
12
My code works now. I found this link useful My link.
Anyway, thank you guys!
kiran123
(Sharmakiran71)
May 7, 2014, 7:04am
14
Thanks to refer my Wiki.
Don’t forgot to give plus (+ve) point