Corrupt Excel Import File

Hello,

In the Import Assistance module any (Products, Third Parties, etc) of the excel import template files I try to download will not open due to the following error:
“Excel cannot open the file ‘Example_of_import_file_produit_1.xlsx’ because the file format of file extension is not valid. Verify that the file had not been corrupted and that the file extension matches the format of the file”

If I open the file in a text editor I see the following:


<br />
<b>Warning</b>: tempnam(): open_basedir restriction in effect. File(C:\WINDOWS\TEMP) is not within the allowed path(s): (c:/dolibarr) in <b>C:\dolibarr\www\dolibarr\htdocs\core\modules\import\import_xlsx.modules.php</b> on line <b>182</b><br />
<br />
<b>Warning</b>: ZipArchive::open(): Empty string as source in <b>C:\dolibarr\www\dolibarr\htdocs\includes\phpoffice\phpexcel\Classes\PHPExcel\Writer\Excel2007.php</b> on line <b>239</b><br />
<br />
<b>Warning</b>: ZipArchive::open(): Empty string as source in <b>C:\dolibarr\www\dolibarr\htdocs\includes\phpoffice\phpexcel\Classes\PHPExcel\Writer\Excel2007.php</b> on line <b>240</b><br />
<br />
<b>Fatal error</b>: Uncaught exception ‘PHPExcel_Writer_Exception’ with message ‘Could not open for writing.’ in C:\dolibarr\www\dolibarr\htdocs\includes\phpoffice\phpexcel\Classes\PHPExcel\Writer\Excel2007.php:241
Stack trace:
#0 C:\dolibarr\www\dolibarr\htdocs\core\modules\import\import_xlsx.modules.php(184): PHPExcel_Writer_Excel2007->save(false)
#1 C:\dolibarr\www\dolibarr\htdocs\imports\class\import.class.php(217): ImportXlsx->write_footer_example(Object(Translate))
#2 C:\dolibarr\www\dolibarr\htdocs\imports\emptyexample.php(88): Import->build_example_file(‘xlsx’, Array, Array, ‘produit_1’)
#3 {main}
thrown in <b>C:\dolibarr\www\dolibarr\htdocs\includes\phpoffice\phpexcel\Classes\PHPExcel\Writer\Excel2007.php</b> on line <b>241</b><br />


This is a fresh installation of Dolibarr.

The CSV template downloads and opens fine.

Thanks in advance.

Hello

Thanks for posting. You have posted your issue in the Bugs on a stable version section.

Kindly post (here) your Dolibarr setup environment as suggested in [url]www.dolibarr.org/t/post-guidelines/16873/1 This will greatly help the community in assisting you where possible.

Hi,
you can check your read/write permission for the file. Make sure it’s enable for read/write

C:\dolibarr\www\dolibarr\htdocs\includes\phpoffice\phpexcel\Classes\PHPExcel\Writer\Excel2007.php


DOLIBARR ENVIRONMENT
- Version: 8.0.1
- Operating System: Microsoft Windows 10 Pro for Workstations
- Web Server: Apache/2.4.9 (Win32)
- PHP: PHP 5.5.12
- Database: MySQL 5.0.45
- URL(s): http://dolibarr/dolibarr/imports/emptyexample.php?format=xlsx&datatoimport=adherent_1&excludefirstline=1&separator=%2C&enclosure="

Thank you for the suggestion. The file was originally set to read only. But changing to read / write has not resolved the issue.

Hi,

The problem is for the import, your serveur php need to create a temporary file.
He tries to do it but your configuration does not allow to create a file in that folder : open_basedir restriction in effect. File(C:\WINDOWS\TEMP)

Need to check the php configuration.

This issue remains unresolved.

While reviewing Projects - Overview, under “List of time consumed on tasks of project”, I have also encountered another similar error:

Warning: is_dir(): open_basedir restriction in effect. File(/TK1810-0001) is not within the allowed path(s): (c:/dolibarr) in C:\dolibarr\www\dolibarr\htdocs\core\lib\files.lib.php on line 101

Line 101 within “files.lib.php” reads as follows:

if (! is_dir($newpath)) return array();

It seems to me there is a privilege not set correctly somewhere that is preventing Dolibarr from writing necessary files.

Hi,

Do you read what I have put above ?
You have a problem of temporary directory in php configuration

Open the php.ini and check :

Find the directive upload_tmp_dir: uncomment the line and change its value to a required path. In this example it is “/var/tmp”:

; Temporary directory for HTTP uploaded files (will use system default if not
; specified).
; http://php.net/upload-tmp-dir
upload_tmp_dir = /var/tmp

Additionally for PHP versions 5.5 and greater, find the directive sys_temp_dir: uncomment the line and change its value to a required path. In this example, it is “/var/tmp”:

; Directory where the temporary files should be placed.
; Defaults to the system default (see sys_get_temp_dir)
sys_temp_dir = “/var/tmp”

Now, add the new path (in our example it is “/var/tmp”) to open_basedir of all domains, so that PHP scripts can access this directory. Use this KB article for assistance.
Note: The record to be added to the php.txt file should be:

open_basedir = {WEBSPACEROOT}{/}{:}{TMP}{/}:/var/tmp

When my excel file catches corruption issue i was frequently encountering “The File Is Corrupted And Cannot Be Opened Excel” Error.

For fixing this error I have tried file extension changing method and it worked.
I have listed the down the completed steps to perform this task. So you can also try that because you are also facing excel file extension error.

Open File Explorer.

  1. Go to the View Tab.
  2. Tick File name extensions under Show/Hide.
  3. Go to the folder where you Excel file is stored.
  4. Right-click on the Excel File.
  5. Select Rename.
  6. Rename “. XLSX” to “. XLS”.
  7. Click Enter once done.