PhpWord mkdir(): Permission denied - codeigniter

Hello I am trying to export a word document on Codeigniter project with XAMPP on mac but I cannot solve the permission problem. I know there are many similar questions but I try many things nothing helps. Here is my save method.
When comment the headers part browser show me 4 Errors. Otherwise I can download the file but in text file same errors again printed.
public function saveWord()
{
$phpWord = new \PhpOffice\PhpWord\PhpWord();
$section = $phpWord->addSection();
$section->addText('Hello World!');
$file = 'HelloWorld.docx';
// header("Content-Description: File Transfer");
// header('Content-Disposition: attachment; filename="' . $file . '"');
// header('Content-Type: application/vnd.openxmlformats-officedocument.wordprocessingml.document');
// header('Content-Transfer-Encoding: binary');
// header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
// header('Expires: 0');
$xmlWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'Word2007');
$xmlWriter->save("php://output");
}
1.Message: mkdir(): Permission denied
Filename: Writer/AbstractWriter.php
2.Message: tempnam(): file created in the system's temporary directory
Filename: Writer/AbstractWriter.php
3.Message: ZipArchive::close(): Failure to create temporary file: No such file or directory
Filename: Shared/ZipArchive.php
4.Type: PhpOffice\PhpWord\Exception\Exception
Message: Could not close zip file php://output:
Filename:
/Applications/XAMPP/xamppfiles/htdocs/kvkkolay/vendor/phpoffice/phpword/src/PhpWord/Shared/ZipArchive.php
I also try to change folder owner with chown -R myusername:mygroup path/to/folder
for permission chmod -R 0777 path/to/folder
In addtion to I also check the php user with whoami the result is daemon.
In the source code of phpword I can see that they are trying to create a temp folder on this path /var/folders/45/zwgpkpmx3kj0hypypctn67rh0000gn/T/PHPWordWriter_635a3ef3f02cf5.54543358 also try to change this folder owner and permission but it returns not permitted.
Could any one help?

Related

How to avoid special chars change on file copy

A customer put once a day a csv file to an ftp server.
With a laravel application, I copy the file to my server.
$files = Storage::disk('xxxxMasterData')->allFiles();
foreach ($files as $file) {
$fileToCopy = Storage::disk('xxxxMasterData')->get($file);
Storage::disk('localXxxxlMasterData')->put($file, $fileToCopy);
if(env('APP_ENV') === 'production') {
Storage::disk('xxxxMasterData')->delete($file);
}
}
The content of the file on the ftp server ist ok. The special chars are ok:
438186|DM1210DWS|D1=4 L1=14 D2=4 L2=50 Z=2|DWS|Schaftfräser|Fraise en bout|
When I open the copied file, the word Schaftfräser has changed to Schaftfr�ser!
It looks like this:
438186|DM1210DWS|D1=4 L1=14 D2=4 L2=50 Z=2|DWS|Schaftfr�ser|Fraise en bout|
I tried to read only the content from the ftp server, but it return also the Schaftfr�ser!
Is there a setting to do on laravel or on the ftp server to avoid this problem?
I had to change the encoding:
$fileToCopyEncoded = mb_convert_encoding($fileToCopy, 'UTF-8', 'ISO-8859-1');

Vimeo uploading Laravel giving -file_put_contents():Write of 207 bytes failed with errno=13 Permission denied

// controller
$file = $request->file('video');
$uri = Vimeo::upload($file, [
'name' => 'test',
'description' => 'easy upload'
]);
return $uri;
file_put_contents(): Write of 207 bytes failed with errno=13 Permission denied
The process running the app needs write permission to the temp directory (defaults to /tmp) for TusUpload to work.
For Laravel $request->file to work, the process also needs write permission to the file directory (this defaults to public/uploads in the root directory of the app, but can be configured)

Copy logs file to another path laravel

I want to get a copy of the logs file using programmability, I just tried to copy the files using this command
$co= Storage::copy('logs/laravel-'.$start.'.log',$filename);
dd($co);
but I have an error which says the file does not exist,
I believe that is because storage looking in the default driver of the config file, how can I tell laravel to look in logs folder when I want to run the copy command, is there any way to do that .
Hi You can get the path of the log file with storage_path() and copy your file anywhere you want with php copy function
I think that is a easy way that you can do it:
<?php
function copyLogFile($logFileName, $destination)
{
$logPathDir = storage_path().'/logs/';
$logFilePath = $logPathDir . $logFileName;
if (file_exists($logFilePath)) {
if( !#copy($logFilePath, $destination) ) {
echo "File can't be copied! \n";
$errors= error_get_last();
echo "COPY ERROR TYPE: ".$errors['type'].PHP_EOL;
echo "COPY ERROR MESSAGE: ".$errors['message'];
}
else {
echo "File has been copied! \n";
}
} else {
echo "The file $logFilePath does not exist";
}
}
// Store the path of destination file
$destination = '/home/azibom/Desktop/backup.log';
// Your log file name
$start = "2020-01-01";
$logFileName = 'laravel-'.$start.'.log';
copyLogFile($logFileName, $destination);
?>

folder created has the user and group as www-data - Laravel

I am trying to create a folder in the app directory but for whatever reason the there is a lock symbol in the folder icon and the user and it's group is www-data.
$folder_path = app_path('core/'.$module);
if (!file_exists($folder_path)) {
File::makeDirectory($folder_path, $mode = 0755, $recursive = false, $force = false);
//mkdir($folder_path, 0777);
exit;
} else {
//
}
When I was trying to create the folder there was a permission denied error so I did chmod -R 777 app/core/ after this when I try to create the user associated to it is www-data.
Why is it www-data and not my username and why is there a lock symbol?
NOTE: Using nginx web server.
As default, nginx and php-fpm will run as user www-data. You can check in your /etc/nginx/nginx.conf and /etc/php/{version}/fpm/pool.d/www.conf
See here if you want to config your web app run as your username.

pdf document error on download

Hello I have some pdf files in my website which the users can download but the problem is when we download these pdf file and try to open the pdf I get an error " There was an error in opening the document. The file is damaged and could not be repaired" but on the contarary this works fine in my local system.
Please guide me , Here is my code
function download_pdf($parameters)
{
$final_link = "$parameters";
$path = strtolower($final_link);
$file = "$path";
if (file_exists($file)) {
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.basename($file));
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($file));
ob_clean();
flush();
readfile($file);
exit;
}
else
{
//echo "file do not exist";
redirect('site/file_does_not_exist');
//$data['main_content'] = 'not_found';
//$this->load->view('includes/template',$data);
}
}
Try using this instead:
...
header('Content-Type: application/pdf');
...
From Internet media types in wikipedia:
application/pdf: Portable Document Format
And also make sure that the file name has the extension ".pdf".

Resources