Yii Framework Forum: Cant Upload Pdf File - Yii Framework Forum

Jump to content

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

Cant Upload Pdf File Rate Topic: -----

#1 User is offline   raowl 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 7
  • Joined: 26-February 10

Posted 16 January 2014 - 02:55 PM

yii-1.1.14.f0fee9.tar.gz i am new but i am not sure why i cant upload file, it shows me "no file selected message" if i put the wrong filename type it validates but with pdf nothing

this are my files:

controller:


public function actionCreate()
{
$model=new Files;

// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);

if(isset($_POST['Files']))
{
$model->attributes=$_POST['Files'];
$filename = CUploadedFile::getInstance($model, 'path');
if ($filename !== null )
{
$rfname = rand(0, 9999) . $filename;
$model->path = $rfname;
}
if($model->save()) {
if ($filename !== null)
{
$path = Yii::app()->basePath . '/../pdfs/' . $rfname;
$model->path->saveAs($path);
}
$this->redirect(array('view','id'=>$model->id));
}
}

$this->render('create',array(
'model'=>$model,
));
}


model:

public function rules()
{
// NOTE: you should only define rules for those attributes that
// will receive user inputs.
return array(
array('name, initial_date, end_date, product_id', 'required'),
array('path', 'file',
'allowEmpty'=>true,
'types'=> 'pdf',
'maxSize' => 1024*1024* 10, // 10MB
'tooLarge' => 'File very big',
'wrongType' => 'Debe ser un archivo pdf'),
array('product_id', 'numerical', 'integerOnly'=>true),
array('name', 'length', 'max'=>128),
// The following rule is used by search().
// @todo Please remove those attributes that should not be searched.
array('id, name, initial_date, end_date, product_id', 'safe', 'on'=>'search'),
);
}
and _form.php

<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'files-form',
// Please note: When you enable ajax validation, make sure the corresponding
// controller action is handling ajax validation correctly.
// There is a call to performAjaxValidation() commented in generated controller code.
// See class documentation of CActiveForm for details on this.
'enableAjaxValidation'=>false,
'htmlOptions'=>
array( 'enctype' => 'multipart/form-data'),
)); ?>
<div class="row">
<?php echo $form->labelEx($model,'path'); ?>
<?php echo $form->fileField($model, 'path'); ?>
<?php echo $form->error($model, 'path'); ?>
</div>

what could be wrong?
0

#2 User is offline   ORey 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,694
  • Joined: 20-April 09
  • Location:Moscow, Russia

Posted 16 January 2014 - 03:09 PM

wtf

$rfname = rand(0, 9999) . $filename; // string
$model->path = $rfname; // string
$model->path->saveAs($path);  // object?..

God is real unless declared as integer
0

#3 User is offline   raowl 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 7
  • Joined: 26-February 10

Posted 16 January 2014 - 03:15 PM

View PostORey, on 16 January 2014 - 03:09 PM, said:

wtf

$rfname = rand(0, 9999) . $filename; // string
$model->path = $rfname; // string
$model->path->saveAs($path);  // object?..



what do you mean? $path is also a string
0

#4 User is offline   ORey 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,694
  • Joined: 20-April 09
  • Location:Moscow, Russia

Posted 16 January 2014 - 03:23 PM

if $model->path is a string, then what will be the result of $model->path->saveAs()?
God is real unless declared as integer
0

#5 User is offline   raowl 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 7
  • Joined: 26-February 10

Posted 16 January 2014 - 03:42 PM

ah my mistake ok, but the same problem... it doesnt even enter the post it seems


if(isset($_POST['Files']))
{
echo "this isnt shown!"
exit;
$model->attributes=$_POST['Files'];
$filename = CUploadedFile::getInstance($model, 'path');
if ($filename !== null )
{
$rfname = rand(0, 9999) . $filename;
$model->path = $rfname;
}
if($model->save()) {
if ($filename !== null)
{
$path = Yii::app()->basePath . '/../pdfs/' . $rfname;
$filename->saveAs($path);
}
$this->redirect(array('view','id'=>$model->id));
}
}

$this->render('create',array(
'model'=>$model,
));
}
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