CSV File Download Fail

About a month ago a file that is created by the Yii database for users to download to their machine started displaying the following error:

[b]Forbidden

You don’t have permission to access /step/files/<filename>.csv on this server.


Apache/2.4.10 (Debian) Server at <servername>.com Port 443[/b]

No changes were made to the Yii configuration by me (and as far as I know I should be the only one able to make these type of changes)

I do not know if an Yii update was done which may have caused this issue.

I can still access the file via Linux, FTP clients, etc. and download them with no issues.

The full url would be like: //<servername>.com/step/files/<filename>.csv (I have confirmed the file is at the proper location)

I am an experienced PHP/HTML/JavaScript programmer. I’ve been programming for over 30 years. Just never use frameworks, automatic code generators or giu programming methods. I prefer just straight coding of systems, that is why I am a programmer after all.

I would appreciate any help I can get to reduce this frustration and get me comfortable using Yii as my customer has chosen it as the framework to use.

John

What are the directory and file permissions for:

[color=#1C2837][size=2]- step[/size][/color]

[color=#1C2837][size=2]- files[/size][/color]

[color=#1C2837][size=2]- <filename>.csv[/size][/color]

[color=#1C2837][size=2]

[/size][/color]

[color=#1C2837][size=2]

[/size][/color]

Hi,

You may try to read and write back to the users by creating a new action?

I don’t know how exactly this will help you!.





public function actionDownloadcsv() {

    $file = "YOUR_PHYSICAL_LOCATION/FILE.CSV";

    $filename = 'YOUR_DESIRED_FILE_NAME';

    if (file_exists($file)) {

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

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

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

        header('Expires: 0');

        header('Cache-Control: must-revalidate');

        header('Pragma: public');

        header('Content-Length: ' . filesize($file));

        readfile($file);

    } else {


        return 'File Does not exists';

    }

    Yii::$app->end();

}



Instead of giving direct file location you can refer this action that would be better choice!

how do you export the files from your database to the filesystem perhaps your file is not being written with read permissions, can you paste your code here?

Full path in Linux would be: <server>.com/mnt/files_step/<filename>.csv

or mnt/step/files - files is a ‘link’ defined to /mnt/files_step

mnt drwxr-xr-x

files_step drwxrwxr-x+

step drwxrwxr-x+

files lrwxrwxrwx

<filename>.csv -rw-r–r--

Thanks, I’ll give this a try.

Haven’t been able to find the code for this. Not sure if it is a CRONN or a built in Yii item.

All I know at this time is it happens daily at 3:00am.

If I find it I’ll let you know.

Thanks!