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

file_put_contents(/vagrant/public/test.pdf8O1RWi): failed to open stream: Permission denied #7

Closed
BnSmth opened this issue Jan 16, 2014 · 4 comments

Comments

@BnSmth
Copy link

BnSmth commented Jan 16, 2014

Me again 😄, I am having varying success with this package...

This is the code I am using at the moment:

$job = Job::findOrFail($index);
$admin = Company::findOrFail(1);
return PDF::loadView('quotes.forward', compact('job', 'admin'))->save('/vagrant/public/test.pdf');

It will stream and download the output but when I try and save it I get the above message. I have tried changing the directory but it makes no difference. A blank file is created in the correct directory with the title matching the error (in this case /test.pdf8O1RWi)

I cannot work out what is causing the random string to be appended at the end of the filename or how to fix this problem.

The output pdf that it is producing when it streams/downloads is excellent.

@BnSmth
Copy link
Author

BnSmth commented Jan 16, 2014

Also this is the method that is throwing the error:

if (false === @file_put_contents($tmpFile, $content)) {
throw new IOException(sprintf('Failed to write file "%s".', $filename), 0, null, $filename);
}

in symfony/filesystem/Symfony/Component/Filesystem/Filesystem.php.

@cangelis
Copy link
Owner

Directory in which you are trying to write, have to be writable.

@BnSmth
Copy link
Author

BnSmth commented Jan 18, 2014

drwxrwxrwx 1 vagrant vagrant 272 Jan 18 15:23 quotes

The directory is writeable so I do not believe that this is the issue.

As I mentioned above every time

return PDF::loadView('quotes.forward', compact('job', 'admin'))->save('/vagrant/public/test.pdf');

is run, a new file is created in the app/storage directory that begins test.pdf but that is followed by a random string. For example, I just ran the function 4 times and this is what was produced within app/storage:

-rw------- 1 vagrant vagrant 0 Jan 18 15:29 test.pdf489Djm
-rw------- 1 vagrant vagrant 0 Jan 18 15:29 test.pdfcRvD0U
-rw------- 1 vagrant vagrant 0 Jan 18 15:29 test.pdfGw2J2Q
-rw------- 1 vagrant vagrant 0 Jan 18 15:29 test.pdfLjF3gk

I had a look through the src but I couldn't see anywhere obvious the random string was being added (though I will admit some of the code went over my head).

@BnSmth
Copy link
Author

BnSmth commented Jan 21, 2014

I'm an idiot, turns out you (and the error message!) were correct all along. Using Vagrant was causing some permission issues which once sorted mean't that this behaved perfectly. Thanks again!

@BnSmth BnSmth closed this as completed Jan 21, 2014
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

2 participants