Microsoft Excel cannot access the file - php

Microsoft Excel cannot access the file
'C:\xxx\test.xls'. There are several possible reasons: • The file name
or path does not exist. • The file is being used by another program. •
The workbook you are trying to save has the same name as a currently
open workbook.
I followed this steps
link
Also I included the extesion "php_com_dotnet.dll" in php.ini.
I have Zend Server CE with php 5.3.14
The issue persist when I reboot the computer.
code::
$file = "C:\\xxx\\test.xls";
try {
$excel = new COM("Excel.Application") or die ("ERROR: Unable to instantaniate COM!\r\n");
$excel->Visible = true;
$Workbook = $excel->Workbooks->Open($file) or die("ERROR: Unable to open " . $file . "!\r\n");
} catch (Exception $exc) {
echo $exc->getMessage();

Things to consider:
Have you checked the permissions of the file? I'm assuming "xxx" is a placeholder for the proper folder name as well?
Do you have file open by something else? Excel perhaps? Excel will grab the file and "lock" it down from use by other things.
What user is the web server running as? Can it access that path?

try the answer from this guy named Aardigspook
in https://www.excelforum.com/excel-general/1182105-excel-cannot-access-the-file-2.html
The problem is a 'Name' . Go to the 'Formulas' tab, click 'Name Manager' and scroll down to the entry named 'special'. It refers to '--filepath--/[xxxxx.xlsx]Sheet1'!$A:$A'. Delete this, or amend it to a reference you have/want, and the error should be gone.
-captain hair.

After searching for a week and 3 times a new office 365 installation, my solution was to replace my faulty Micro-SD adapter.

Related

A way to change the ownership of Apache to order creating txt file

Could you please tell me how to change Apache ownership in Windows if you guys know, since I cannot create txt files using PHP without permission. According to my issue, I need to be able to authorise a file to be made.
What I am trying to do is create a script that records keystrokes in the Firefox extension section. This script will send the data to an Apache PHP file and store it in a text file. I would appreciate your response if you could.
<?php
session_start();
if (!isset($_POST['key'])) {
echo ("Didn't received any new KEY strokes Yet!");
exit(0);
}
//read and write = a+, If the file does not exist, attempt to create it
$file_log = fopen("key.txt","a+");
if (!isset($_SESSION['site']) || $_SESSION['site'] != $_POST['site']) {
$_SESSION['site'] = $_POST['site'];
fwrite($file_log, "| site : ".$_POST['site']." | ");
}
fwrite($file_log,$_POST['key']);
fclose($file_log);
echo("text saved successfully");
It looks like you are not defining a full path for the file.
Depending on where php is running just calling fopen("key.txt","a+") might default to the root directory.
When creating/modifying files you should specify the full path to the file
fopen("/var/www/mydir/example/path/key.txt","a+")

Failed to Send File to another computer on the same network using PHP

We're making a Foodlist site which has an Admin that has the privilege to "Add Food" and "Edit Food" which includes giving images. But all trials to send the food image to the actual computer we're going to use as a server has failed. It'd be weird to copy the image everytime we edit something or add something.
Our site requires us to simply send a file from our computer to another in their "xampp\htdocs\sitepage\images" folder. We're on the same network. Here's our code.
$my_file = 'C:\Users\ASUS\DownloadsMyFile.jpg';
/* New file name and path for this file */
$destination_file = '192.168.1.105/sitepage/images/INeedSomeRest.jpg';
/* Copy the file from source to server */
$copy = copy( $my_file, $destination_file );
/* Add notice for success/failure */
if( !$copy ) {
echo "It didn't work.";
}
else{
echo "WOOT! Successfully copied the file.";
}
It always gives us an error such that the browser says something like:
" failed to open stream: No such file or directory in ~our php file~ "
Is there something we're doing wrong? That being said, is there another way to send a file to another computer via PHP?
A Response will be greatly appreciated. Thank you in advance.
It seems I took the "copy" method of php all wrong. it seems it can only take a file from another server to your computer, and not the other way around. To the people who have the same problem as me, try to read about File Transfer Protocols. =) I appreciate all the replies. Thank you.
1) Try to use $destination_file = 'http://192.168.1.105/sitepage/images/INeedSomeRest.jpg'; (note about http://)
2) Make sure that you CAN write to that resource (enough rights, shared properly, etc)

PHP COM Object to Open Word 2013, Count Pages Not Wkg for .docm

I am using a PHP COM Object to Open a Word 2013 file and count pages. My code works great for .docx files but not for .docm files. I am using php 5.4 and IIS 7.5 in a Windows 2008 R2 environment. Any recommendations?
// Create an instance of the Word application
$word = new COM("word.application");
if ($word) {
// Open the document
$word->Documents->Open($file_dir . $filename);
// Get the page count
$pagecount = $word->Documents[1]->ComputeStatistics(2);
}
You could try to turn off all macros like this before opening a file, this also disable security prompts:
$word->AutomationSecurity = 3; // disable all macros in the documents being opened
Well, doesn't .docm signify that there are macros or event macros present in the file?
Usually when the user opens a .docm file, the user is given a security prompt. Being that you are running under PHP, you might be running under a service and the prompt is not being seen in the hidden desktop, or security it preventing it from running at all. I would suggest you write some VBS code to try and open the same file under a console and see what the results are. If you get prompts or its being prevented, hopefully you will get better error messages.
var word
set word = CreateObject("Word.Application")
word.documents.open("path to my file")
var pageCount
pageCount = word.Documents(1).ComputeStatistics(s)

Saving Archive Comment to ePub file

I am working on a PHP application which downloads an ePub file. As part of the code I am adding a unique identifier which can be used to trace the original download information in a database to combat piracy.
I am using PHP ZipArchive functions to add an archive comment to the file but it seems that Adobe Digital editions is unable to open the ePub file if there is a comment present. When the comment is removed it opens fine so I just want to see if anyone else has had this problem before and if there is a way to add a comment to the ePub file which will allow Adobe Digital Editions to open it. Below is the code I'm using:
public function secureEpub($file, $download_id, $filepath){
//GENERATE RANDOM FILE NAME
$newFile = uniqid().".epub";
//COPY EPUB AND WORK FROM THAT VERSION
copy($file, $filepath.$newFile);
//TREAT EPUB FILE AS ORDINARY ZIP ARCHIVE
//OPEN AND EXTRACT EPUB
$zip = new ZipArchive;
$res = $zip->open($filepath.$newFile);
if($res === TRUE){
//ZIP ARCHIVE HAS OPENED SUCCESSFULLY - SET ARCHIVE COMMENT TO DOWNLOAD ID
$zip->setArchiveComment($download_id);
$zip->close();
} else {
error_log('Unable to open ePub (' . $filepath.$newFile . ') as Directory');
return false;
exit;
}
//ONCE CHANGE HAS BEEN MADE CLOSE THE ARCHIVE AND RETURN TEMP FILE
return $filepath.$newFile;
}
As you can see it copies the original, creates an Archive comment then returns the file (which is later deleted). Is there a way of achieving this without corrupting the ePub (for ADE)?
Let me know if I've not made any sense :D
P.S: Just to clarify, the download works fine and the comment is applied correctly. It is just that ADE is unable to open it while other ePub readers manage fine. Am I going about it in the wrong way?
OK, I couldn't find a way around this so I kind of came up with a solution. You can add a new file or directory inside the ZIP file which had the details included.
So, you can use something like:
$zip->addFromString('test.txt', $download_id);
or create a directory named after the download like:
$zip->addEmptyDir($download_id);
Would probably recommend being a bit more obscure with naming though if you get stuck like I did :)
Thanks

Using Office Word to read doc files with PHP

I am trying to use PHP with word.application to read a file. It simply will not open the file. It's echoing the right version.
$w = new COM("word.application") or die("Is office installed?");
echo 'Loaded Word, version ' . $w->Version . '<br>';
$w->Visible = false;
$w->Documents->Open(realpath('test.docx'));
$content = (string) $w->ActiveDocument->Content;
echo $content;
$w->Quit();
$w->Release();
$w = null;
I get the error:
Uncaught exception 'com_exception' with message 'Source: Microsoft Word
Description: This command is not available because no document is open.'
It feels like it's some kind of permission problem. I tried to put the path of the test.docx besides using realpath and that did not help. Also tried to put it in the root of my C drive. I am using Windows 7 Professional and Microsoft Office 2007.
Documents->Open returns a document if all is ok. Probably, the document does not exists (path incorrect), or you haven't got the rights to open it from PHP. Store the result in $var, check if it has an appropriate value (probably not isset, null or false if not), and use $var->Content to read the content.
Try doing a file_exists on said
file/path.
If that works, try
file_get_contents and see if you can
read it.
If that all works - then it's not a problem with permissions/etc.

Categories