Closed karunkshrestha closed 10 years ago
Hey,
Could you provide the code you used and the Laravel version.
laravel 4.1 + Frozennode\Administrator + Maatwebsite\Excel
-------------------------- frozennode administrator model --------- ajax to return the file. return array( /**
/**
/**
/**
/**
/**
/**
'global_actions' => array( 'export_to_excel' => array( 'title' => 'Export To Excel', 'messages' => array( 'active' => 'Exporting...', 'success' => 'Spreadsheet created!', 'error' => 'There was an error while creating this spreadsheet', ), 'action' => function($query) {
$result = $query->get();
Excel::create('TestCSVCase')
->sheet('SheetName')
->with($result->toArray())->save('csv');
}
),
),
); ?>
I tried the Excel part of the code and it just works fine. When I changed the writing permission, I got your error. After changing back to 777, it works again. Are you sure the store folder has the correct writing permission, else this error would not be triggered...
I have taken the excel code out of the laravel administrator section and put it staight into the routes.php
Route::get('courses',function(){ $result = Courses::all(); Excel::create('TestCSVCase') ->sheet('SheetName') ->with($result->toArray())->save('csv'); });
and i still get the error
I have set full control permission on the 'exports' folder.
still getting the same error.
Are you using WAMP?
I am using iis 7, php 5.5 and mysql 5
On 3 Feb 2014 17:27, Maatwebsite notifications@github.com wrote: Are you using WAMP?
Reply to this email directly or view it on GitHub: https://github.com/Maatwebsite/laravel4-PHPExcel/issues/16#issuecomment-33978075
I'm afraid I can't help you with IIS, I only work with LAMP stacks. I'm sure it has to do with the write permissions, but I have no idea how this works with IIS.
thanks for information. I will try to look into the IIS security settings to see if that is what is causing the error
I have found a fix for it, It looks like you have not considered the windows filepath syntax when saving the excel object. I have changed the line number 506 in Excel.php so that didn't contain the leading slash in the filepath. it might be a good idea to have both unix and windows filepath when saving the object.
public function store($ext = 'xls', $path = false)
{
// Set the default path
if($path == false)
{
$path = Config::get('excel::path');
}
// Trim of slashes, to makes sure we won't add them double.
$path = rtrim($path, '/');
$path = ltrim($path, '/');
// Set the extension
$this->ext = $ext;
// Render the XLS
$this->render();
// Save the file to specified location
//$this->object->save('/' .$path . '/' . $this->title . '.' . $this->ext);
$this->object->save($path . '/' . $this->title . '.' . $this->ext);
}
+1 to this... $this->object->save($path . '/' . $this->title . '.' . $this->ext);
worked for me too...
So, now when I try to use store() with a path, I can't use storage_path() because the front backslash in the path is stripped by the ltrim on line 538 (I'm on a Mac). How am I supposed to store? :-)
Edit: What I am trying to say is that I can't use absolute paths on unix systems anymore?
Could you try if it works now.
It does :-)
I get this error when trying to save csv file to a folder. The folder itself has write permission set correctly.
{"error":{"type":"ErrorException","message":"fopen(\/C:\inetpub\wwwroot\learning\laravel-administrator-crud\/exports\/TestCSVCase.csv): failed to open stream: Invalid argument","file":"C:\inetpub\wwwroot\learning\laravel-administrator-crud\vendor\phpoffice\phpexcel\Classes\PHPExcel\Writer\CSV.php","line":111}}