Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

failed to open stream: invalid argument #16

Closed
karunkshrestha opened this issue Feb 3, 2014 · 13 comments
Closed

failed to open stream: invalid argument #16

karunkshrestha opened this issue Feb 3, 2014 · 13 comments

Comments

@karunkshrestha
Copy link

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}}

@MaatwebsiteSupport
Copy link
Contributor

Hey,

Could you provide the code you used and the Laravel version.

@karunkshrestha
Copy link
Author

laravel 4.1 + Frozennode\Administrator + Maatwebsite\Excel

-------------------------- frozennode administrator model --------- ajax to return the file.
return array(
/**

  • Model title
    *
  • @type string
    */
    'title' => 'Race Courses',

/**

  • The singular name of your model
    *
  • @type string
    */
    'single' => 'Race Course',

/**

  • The class name of the Eloquent model that this config represents
    *
  • @type string
    */
    'model' => 'course',

/**

  • The columns array
    *
  • @type array
    */
    'columns' => array(
    'courseKey'=> array(
    'title' => 'courseId'
    ),
    'name' => array(
    'title' => 'Course Name'
    ),
    'type' => array(
    'title' => 'Course Type'
    ),
    'postcode' => array(
    'title' => 'Postcode'
    )
    ),

/**

  • The edit fields array
    *
  • @type array
    */
    'edit_fields' => array(
    'name' => array(
    'title' => 'Course Name',
    'type' => 'text'
    ),
    'type' => array(
    'title' => 'Course Type',
    'type' => 'text'
    )
    ),

/**

  • The filter fields
    *
  • @type array
    */
    'filters' => array(
    'courseKey',
    'name' => array(
    'title' => 'Course Name',
    ),
    'type' => array(
    'title' => 'Course Type',
    'type' => 'text',
    ),
    ),

/**

  • The width of the model's edit form
    *
  • @type int
    */
    'form_width' => 400,

'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');
    }
),

),

);
?>

@MaatwebsiteSupport
Copy link
Contributor

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...

@karunkshrestha
Copy link
Author

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
image

I have set full control permission on the 'exports' folder.

still getting the same error.

@MaatwebsiteSupport
Copy link
Contributor

Are you using WAMP?

@karunkshrestha
Copy link
Author

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:
#16 (comment)

@MaatwebsiteSupport
Copy link
Contributor

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.

@karunkshrestha
Copy link
Author

thanks for information. I will try to look into the IIS security settings to see if that is what is causing the error

@karunkshrestha
Copy link
Author

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);
    }

@mewben
Copy link
Contributor

mewben commented Feb 5, 2014

+1 to this... $this->object->save($path . '/' . $this->title . '.' . $this->ext); worked for me too...

@hm-n2ads
Copy link

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?

@MaatwebsiteSupport
Copy link
Contributor

Could you try if it works now.

@hm-n2ads
Copy link

It does :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants