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

Impossible to open /results/Sample_07_TemplateCloneRow.docx (windows only) #532

Closed
AshSat opened this issue May 6, 2015 · 32 comments
Closed

Comments

@AshSat
Copy link

AshSat commented May 6, 2015

Hello,

I have a problem with templates, using a WAMP server.
I don't have any issue with the same process with a LAMP server.

It's a LOCAL application, NOT on the internet.
Word documents have been tested with LibreOffice and OpenOffice, same results.

I'm working with the Sample_07_TemplateCloneRow example.
With Linux :
It works perfectly,
I can open the file via http://...., but it is a "read only" version (that's fine, but NOT what I need)
I can open, read and modify the "/results/Sample_07_TemplateCloneRow.docx" file in his folder (direct access in the folder)

With Windows 7 (I tried with 2 different computers, same issue)
I can open the file via http://, it works but it's NOT what I need !
I can save the document in my "downloads" folder. After that, I can open the new document but it is NOT what I need neither !

I CANNOT open the "c:/[...]/results/Sample_07_TemplateCloneRow.docx", the file is "corrupted" (access denied) but it IS this one I need to open !

After many, many, many tests, I found a way to open those files :
right-click on the file -> Properties -> Security -> Modify -> Add a user -> I added my windows "username" (my OS is in french, i'm not quite sure with the english labels !)

and then, it works, I can open my "c:/[...]/results/Sample_07_TemplateCloneRow.docx"
It works, but it's really not an easy way for a daily use.

Templates (07 & 23) are the only ones who makes troubles.
IE, "/results/Sample_06_Footnote.docx" didn't need any manipulation before beeing open and have no owner neither.
I have no problem with other generated files with or without PHPWord, only with those using TemplateProcessor.

I do not understand what's the problem and think a little bit ironic to have rights/permissions issues with windows...

Has someone a solution with this issue ?
How can I solve it ?

Without this problem, PHPWord is awesome !

Windows 7 64bits
Wamp Server 2.5
Apache 2.4.9 (Win 32)
php 5.5.12
PHPWord Master 0.12.0

@ghost ghost added the Consulting Request label May 6, 2015
@ghost ghost self-assigned this May 6, 2015
@ghost
Copy link

ghost commented May 6, 2015

Hi @AshSat,
Which LibreOffice version did you try?

UPD:
By the way, try playing with PHPWord temp dir location (see phpword.ini). PHPWord uses system temp dir by default. Maybe this is somehow connected with the security restrictions.

@ghost
Copy link

ghost commented May 11, 2015

Any news, @AshSat?

@AshSat
Copy link
Author

AshSat commented May 11, 2015

Hi,
Sorry, I didn't your messages.
I tried with LibreOffice 4.3 and OpenOffice 4.1.1

I didn't see any issue with the temp dir.

Open those 2 documents are the only issues. Thanks a lot !

@ghost
Copy link

ghost commented May 11, 2015

Do you experience the issue with the samples only, or it appears each time you use TemplateProcessor?

@AshSat
Copy link
Author

AshSat commented May 11, 2015

Each time I use TemplateProsessor.
With my own samples AND with the original samples.

@ghost
Copy link

ghost commented May 12, 2015

Which temp dir do you use with PHPWord, default?

@AshSat
Copy link
Author

AshSat commented May 12, 2015

yes, the default one.

@ghost
Copy link

ghost commented May 12, 2015

By default, PHPWord uses OS's temp dir. TemplateProcessor copies the provided template into it, performs the transformations you want and saves the result in a new place.

My assumption is that something may happen with file permissions during the trip. So, please, create your own dir somewhere you definetely has enough permissions and give it to PHPWord as temp dir. Maybe this will help.

By the way, I use Windows 7 too and can't reproduce the problem. Possibly this is because I work under account with administrator's privileges.

@andrew-kzoo
Copy link
Contributor

I cannot comment directly to your exact setup. However, I have had ongoing troubles with temporary files and temporary folders when using PHPWord (not just for templates). I concur that creating and using your own temp folder avoids many problems.

@AshSat
Copy link
Author

AshSat commented May 12, 2015

I tried and it works !
It was the problem, you were right !
I created my own temporary dir and the problem is solved !

Thank you very much ! Have a very nice day !

@AshSat AshSat changed the title Impossible to open /results/Sample_07_TemplateCloneRow.docx (windows only) [Solved] Impossible to open /results/Sample_07_TemplateCloneRow.docx (windows only) May 12, 2015
@ghost ghost added the Status: Responded label May 13, 2015
@ghost ghost closed this as completed May 13, 2015
@ghost
Copy link

ghost commented May 15, 2015

Hi @AshSat,
I tried to reproduce your problem to find a remedy and no luck.

Could you, please, switch back to the default temp dir, then add chmod($fileName, 0666); after rename command in TemplateProcessor::saveAs, and let me know if it helps?

Thanks.

UPD: finally, the method should look like this.

public function saveAs($fileName)
{
    $tempFileName = $this->save();

    if (file_exists($fileName)) {
        unlink($fileName);
    }

    rename($tempFileName, $fileName);
    chmod($fileName, 0666);
}

@AshSat
Copy link
Author

AshSat commented May 16, 2015

Hi Roman,
I did it, but it doesn't work.
(I have tried that too before asking my question here, but I did it again, exactly as you ask and it doesn't work).

@ghost
Copy link

ghost commented May 16, 2015

Okay, another attempt. 😄 What happens if you copy the file from it's location (c:/[...]/results/Sample_07_TemplateCloneRow.docx) to another location using Windows Explorer and try to open it then? You'll got the same error or no?

@ghost
Copy link

ghost commented May 26, 2015

@AshSat, are you still there?

@kumfo
Copy link

kumfo commented May 26, 2015

@RomanSyroeshko I also have a broblem,I can't create pdf file.why?

@ghost
Copy link

ghost commented May 26, 2015

@kumfo, how this is connected with the issue?

@AshSat
Copy link
Author

AshSat commented May 27, 2015

Hi Roman,
Sorry, I'm late, but I'm here.
I made a copy of the document on my desktop and I can open it. It works with no error.

@ghost
Copy link

ghost commented May 27, 2015

If we assume that your desktop resides on the same volume (C:), Windows retains original file permissions. It means that the problem is not in file permissions. Our experiment with chmod($fileName, 0666) confirms that.

So, I can suppose that the problem hides somewhere in file path. Can you reveal full file path? Maybe it's simply too long?

@AshSat
Copy link
Author

AshSat commented May 29, 2015

Hi,
The real path is : c:\test\www\PHPWorld-master\samples\

For now, the only solution working is to create a temporary dir.

@ghost
Copy link

ghost commented Jun 2, 2015

The path looks OK. 😞

Your Windows temp dir is in its default location?

@AshSat
Copy link
Author

AshSat commented Jun 2, 2015

Yes, it's sad... and my windows temp dir is in its default location.(sorry)
I know it's frustrating, BUT, the problem is really solved with a temporary dir (in PHPWord) and it's very simple to do.
Adding a simple line in the FAQ will help those who have the same issue.
I really thank you for your time and your help ! I'm happy to help if you have other ideas !

@ghost
Copy link

ghost commented Jun 3, 2015

No pain, no gain. :-)

How many Windows users are involved? I use the same user to run Apache, PHP, LibreOffice, everything. It belongs to Administrators, and all the environment was installed under this account. What about you?

@AshSat
Copy link
Author

AshSat commented Jun 3, 2015

the same... I'm the only user, no other account. All the environment was installed under this account too.

@ghost
Copy link

ghost commented Jun 15, 2015

You know, I even installed WAMP Server, but it didn't help. It just works. 😞

What are the values of BuildLabEx, CurrentVersion, EditionID keys located in HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion folder of your system's registry?

@AshSat
Copy link
Author

AshSat commented Jun 17, 2015

Requirement check:
PHP 5.3.3 ... passed
PHP extension XML ... passed
Temp folder "C:\windows\TEMP" is writable ... passed
PHP extension ZipArchive (optional) ... passed
PHP extension GD (optional) ... passed
PHP extension XMLWriter (optional) ... passed
PHP extension XSL (optional) ... passed

The keys :
BuildLabEx 7601.18798.amd64fre.win7sp1_gdr.150316-1654
CurrentVersion 6.1
EditionID Professional

I hope it helps :)

@ghost
Copy link

ghost commented Jun 17, 2015

Nope. Mine is "7601.18869.amd64fre.win7sp1_gdr.150525-0603". Home Basic edition.

I'll try to find a PC with clean Windows installation. Maybe I customized something on my own laptop and successfully forget about that...

@ghost
Copy link

ghost commented Jun 22, 2015

@AshSat, I got it reproduced on clean installation of Windows 8.1. Will try to find the root cause.

@AshSat
Copy link
Author

AshSat commented Jun 22, 2015

I'm happy you can reproduce the problem !
It's a little strange to be happy when you have a bug ;)

@ghost
Copy link

ghost commented Jun 25, 2015

@AshSat, I found it. Everything works if you change location of temp dirs in Windows (see here for the details). I followed this practice for ages, so it was hard to find.

The next thing is about rename function. As per this post, the function looses file owner. So, in TemplateProcessor I replaced this peace of code

public function saveAs($fileName)
{
    $tempFileName = $this->save();

    if (file_exists($fileName)) {
        unlink($fileName);
    }

    rename($tempFileName, $fileName);
}

with this one

public function saveAs($fileName)
{
    $tempFileName = $this->save();

    if (file_exists($fileName)) {
        unlink($fileName);
    }

    copy($tempFileName, $fileName);
    unlink($tempFileName);
}

and it helped. It works even with default temp dirs.

Could you, please, check if the latter solution works for you?

Thanks.

@ghost ghost reopened this Jul 2, 2015
@ghost ghost changed the title [Solved] Impossible to open /results/Sample_07_TemplateCloneRow.docx (windows only) Impossible to open /results/Sample_07_TemplateCloneRow.docx (windows only) Jul 2, 2015
@ghost ghost added this to the 0.13.0 milestone Jul 2, 2015
@AshSat
Copy link
Author

AshSat commented Jul 2, 2015

Sorry, I'm late, I haven't seen your message before :(
I tried and it works !

Thank you very much !

ghost pushed a commit that referenced this issue Jul 2, 2015
ghost pushed a commit that referenced this issue Jul 2, 2015
ghost pushed a commit that referenced this issue Jul 2, 2015
@ghost
Copy link

ghost commented Jul 2, 2015

Well done, partner! 👍

@ghost ghost closed this as completed Jul 2, 2015
@ghost ghost modified the milestones: 0.12.1, 0.13.0 Aug 16, 2015
ghost pushed a commit that referenced this issue Aug 16, 2015
ghost pushed a commit that referenced this issue Aug 16, 2015
@xarisavee
Copy link

Hi. I think I'm having the same problem. I got this:

Uncaught exception 'PhpOffice\PhpWord\Exception\CopyFileException' with message 'Could not copy 'filename.docx' file to 'C:\xx\xx\AppData\Local\Temp\Php2E68.tmp'.' in C:\xampp\htdocs\lyrics\PHPWord-master\src\PhpWord\TemplateProcessor.php:

How do I "create your own dir somewhere you definetely has enough permissions and give it to PHPWord as temp dir"?

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

No branches or pull requests

4 participants