I want to upload a Excel spreadsheet from the client and then on the server read the spreadsheet and write data to MySQL. I have no need to retain the spreadsheet on the server. I just need to make DB updates. I have phpexcel installed and am able to build and download spreadsheets to the client with no issue.
I am able to display a form, collect the file name, and submit the form. When I try to create a reader with:
$reader = PHPExcel_IOFactory::createReaderForFile($fileName);
I get:
include(PHPExcel_IOFactory.php): failed to open stream: No such file or directory
Can anyone offer suggestions to help me figure out what I am doing wrong? I want to use phpexcel but am not married to this particular approach so I am very open to criticism or suggestions.
Thx
class TransactionsUploadController extends Controller
{
public function actionCreate()
{
$model=new TransactionsUpload;
if(isset($_POST['TransactionsUpload']))
{
$model->attributes=$_POST['TransactionsUpload'];
$model->uploadedFile=CUploadedFile::getInstance($model,'uploadedFile');
$fileName = $model->uploadedFile->getTempName();
echo $fileName;
$reader = PHPExcel_IOFactory::createReaderForFile($fileName);
$objPhpExcel = $reader->load($fileName);
foreach($objPhpExcel->getWorksheetIterator() as $worksheet){
echo $worksheet->getTitle();
// will do work here.......................
}
}
$this->render('upload', array('model'=>$model));
}
}
class TransactionsUpload extends CFormModel
{
public $uploadedFile;
public function rules()
{
return array(
array('uploadedFile', 'file', 'types'=>'xlsx'),
);
}
}
$form = $this->beginWidget(
'CActiveForm',
array(
'id' => 'upload-form',
'enableAjaxValidation' => false,
'htmlOptions' => array('enctype' => 'multipart/form-data'),
)
);
// ...
echo $form->labelEx($model, 'uploadedFile');
echo $form->fileField($model, 'uploadedFile');
echo $form->error($model, 'uploadedFile');
echo CHtml::submitButton('Submit', array('name'=>'submit'));
// ...
$this->endWidget();