Dynamic File Export

I have a csv file export using ECSVExport class.

I have it working on my local computer running WAMP. The url would be http://localhost/example.

But it does not work on a remote server, where the url would be http://www.example.com. I get a "file not found" error (not Yii generated and does not show 404 either).

Both have mod_rewrite enabled, so I think it has something to do with that.

But just incase below is my export script

      $where = "";

            for($i = 0; $i < $_GET['count']; $i++){

                $where .=  't.id='.$_GET[$i].' OR ';


            $where = substr($where, 0, strlen($where)-4);


            $data = Yii::app()->db->createCommand("SELECT category.name AS Category, subCategory.name AS Subcategory, t.Name, company.name AS Supplier, brand.name AS 'Sub-brand', t.percentRecycledContent, CONCAT('".Yii::app()->createAbsoluteUrl('product/view')."/', t.id) AS Link  FROM Product `t` LEFT OUTER JOIN `company` `company` ON (`t`.`companyId`=`company`.`id`)  LEFT OUTER JOIN `productcategory` `category` ON (`category`.`id`=`t`.`categoryId`)  LEFT OUTER JOIN `productcategory` `subCategory` ON (`subCategory`.`id`=`t`.`productSubCategoryId`) LEFT OUTER JOIN companyBrand brand ON (brand.id = t.companyBrandId) LEFT OUTER JOIN `wishlistproduct` `wishlist` ON (`wishlist`.`ProductId`=`t`.`id`)  WHERE ".$where);

            $filename = 'wishlist-export-'.date('d-m-Y').'.csv';



            header("Cache-Control: public");

            header("Content-Description: File Transfer");

            header("Content-Disposition: attachment; filename=".$filename);

            header("Content-Type: application/csv");

            header("Content-Transfer-Encoding: binary");

            $csv = new ECSVExport($data);

            echo $csv->toCSV(); 

My local .htacces file is:

RewriteEngine On

RewriteBase /example

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^(.*)\?*$ index.php/$1 [L,QSA]

And the remote .htaccess file is:

RewriteEngine On

RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^(.*)\?*$ index.php/$1 [L,QSA]

What I am doing wrong to on the server to cause this?

Thank you in advance.

Hi Stephen,

What exactly is the error message? What file does it say is missing?

Well, I guess that it’s a case sensitivity issue of the file names. Check if all the ECSVExport files are uploaded with the correct names.

Thank you for your response.

I have checked that ECSVExport has been upload and it has. The names should be correct as it works on my laptop where I do the coding.

I have included an screenshot of the error.



It does not give much away, could it be folder permissions? - I have chmod 777 httpdocs folder and still have the same problem.

Seems like this is echoing empty string.

BTW, do not construct the sql like the following. It’s not secure at all.

Thank for pointing me in the right direction, I had problems with the SQL - having capitals in the table names. Strange that WAMP allowed it and the remote server did not.

How would you secure the SQL?

That’s one of the reasons why the conventions for database tables and columns recommend lower case + underscore. :)


You should not use the raw values of $_GET (or $_POST) in the sql.


Thank you for your reply, sorry for taking so long to reply and say thank you.

I eventually secured the SQL through using the CDbCriteria.condition variable to set the CDbCommand.where variable. I thought it was quite ingenious and saves me manually securing and creating the where clause and as I had it created anyway within a search function that I used else where.