I love yii and deeply appreciate the help this forum has provided!
Admittedly my best programming days are behind me, but I have an issue that’s vexing me. I had this prototype running on my Windows 7 laptop (yii/php/apache/postgres), and when I went to move it to a linux server, my file uploads broke.
At first I thought it was the sessions, but I resolved that.
Then I thought it was permissions (the copied php files didn’t have the execute bit set), but that seems to be okay now.
Been fighting it for many hours now, and I can’t figure out what the issue is.
I have this in my "Files" controller for uploading & encrypting files:
public function actionCreate()
{
$model=new Files;
$securityManager = new CSecurityManager;
$securityManager->setEncryptionKey(Yii::app()->params['fileEncryptKey']);
if(isset($_POST['Files']))
{
$model->attributes=$_POST['Files'];
$fdate=$_POST['filedate'];
$model->filedate=$fdate;
$model->url=CUploadedFile::getInstance($model,'url');
// The following encrypts the file.
$tmpfile = CUploadedFile::getInstance($model,'url');
$tmpfile_contents = file_get_contents( $tmpfile->tempName );
$encfile_contents = $securityManager->encrypt(base64_encode$tmpfile_contents));
file_put_contents( $tmpfile->tempName, $encfile_contents );
$model->filename = $model->url;
//$ffilename=$model->filename;
$pid=$model->patient_id;
// Create the directory if it doesn't exist
if (is_dir(Yii::app()->basePath.'/datafiles/'.$pid)) {
/* */
} else {
mkdir(Yii::app()->basePath.'/datafiles/'.$pid) ;
}
//var_dump($_FILES);die;
if($model->save()) {
$model->url->saveAs(Yii::app()->basePath.'/datafiles/'.$pid.'/'.$model->url);
//$model->url = $model->url;
$this->redirect(array('view','id'=>$model->id));
} else {
print_r($model->getErrors());
throw new CHttpException(403,'Unable to save this file!');
}
}
I originally had the "saveAs" before the "if($model->save)" and that yielded an encrypted file (in the final location) with a file name of "Object id #49" on linux, instead of "familypicutre.jpg" on Windows.
The behavior I am seeing is:
PHP error
Object of class CUploadedFile to string conversion
when it goes to do the validation during the save operation.
I also inserted a “var_dump($_FILES);die;” before the “save” on both Windows and linux, and they showed the exact same thing (other than the path diffs b/w the os’s).
It’s confusing, because the error looks like it’s at the yii level, so I don’t understand what the environment has to do with it. I think the real issue is that I don’t really understand how the $model->url can act as a filename as well as a CUploadedFile object, but I based this off of an example, and I got it to work in Windows…
Any ideas??? Thx!