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

sys_get_temp_dir() not writeable on some shared hosts #310

Closed
iflow opened this issue Jul 9, 2014 · 12 comments
Closed

sys_get_temp_dir() not writeable on some shared hosts #310

iflow opened this issue Jul 9, 2014 · 12 comments

Comments

@iflow
Copy link

iflow commented Jul 9, 2014

On some shared hosts / webspaces the sys_get_temp_dir() is not accessable / writeable.
Therefore a new Template can not be generated. The following Exception is thrown:
"'Could not create temporary file with unique name in the default temporary directory.'"

$this->tempFileName = tempnam(sys_get_temp_dir(), '');

I think the path, where the temporary files are stored should be configurable. So you can easily create a temp folder on your webspace and let PHPWord store the temp files there.

@ghost
Copy link

ghost commented Jul 10, 2014

Ugh. Thanks for the report, @iflow. Good point. I will implement some alternative.

@ghost ghost self-assigned this Jul 10, 2014
@ghost ghost added Template and removed Question labels Jul 10, 2014
@ghost ghost added this to the 0.12.0 milestone Jul 10, 2014
@ghost
Copy link

ghost commented Jul 21, 2014

@iflow, do you mean that sys_get_temp_dir() returns an absolutely valid path, yet tempnam() can't access it and returns false?

@iflow
Copy link
Author

iflow commented Jul 25, 2014

@RomanSyroeshko Yes that's what exactly happening

@ghost
Copy link

ghost commented Aug 10, 2014

@iflow, could you please test the implementation?

Use Settings::setTempDir() or the ini-file setting to set user defined temporary directory.

@iflow
Copy link
Author

iflow commented Sep 10, 2014

Sry for the late response: I'm not sure how to use the new function.

\PhpOffice\PhpWord\Settings::setTempDir($tmpdir);

And I'm not sure if it would work, because Template::__construct has not changed. There is still the line with tempnam, which does not use the user defined temporary directory.

 $this->tempFileName = tempnam(sys_get_temp_dir(), '');

@andrew-kzoo
Copy link
Contributor

I saw this issue and thought maybe the PclZip component needs to be configured to use this new Settings:setTempDir() temporary directory setting, too. See #265 for a bit more information.

I can't look into this presently. I wanted to put a note out there for others who have need for, experience with, or been troubled by pesky errors reading and writing files in the system temporary directory.

@iflow
Copy link
Author

iflow commented Sep 10, 2014

Hi, thanks @andrew-kzoo
I solved the issue with modifying the __construct of Template.php:

$this->tempFileName = tempnam(getcwd() . '/mytemp', 'phpWord'); // Custom fix

You see, I through my own temporary directory to the tempnam function to fix the issue. It's not a nice solution, because it does influence future PhpWord updates. However this workaround works and so far I'm happy with it.

@ghost
Copy link

ghost commented Sep 13, 2014

@iflow, those line you mentioned looks like that now:

$this->temporaryDocumentFilename = tempnam(Settings::getTempDir(), 'PhpWord');

The fix was put in develop branch only. It's not released yet. So, could you please take a look into develop branch?

@ghost
Copy link

ghost commented Oct 3, 2014

Any news, @iflow?

@iflow
Copy link
Author

iflow commented Oct 5, 2014

It works now (using develop branch)! Thank you.

@Progi1984
Copy link
Member

Good job @RomanSyroeshko ;)

@ghost
Copy link

ghost commented Oct 6, 2014

It was a genuine pleasure for me. :)

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

No branches or pull requests

3 participants