Yii 2 Saving file to a particular folder while Using PHPexcel - php

I tried to save the file into a specific folder using the following code from a stack overflow thread PHPExcel Save a xls file to a specific folder
$objWriter->save(str_replace(__FILE__,'folder_path/filename.xlsx',__FILE__));
Since I am using yii 2 I tried this method
$objWriter->save(str_replace(__FILE__,Yii::getAlias('#web') .'/files/MyContacts.xlsx',__FILE__));
But it is not working the file still creates in the web (root folder). Is there a solution for the same ?
The error message i get is "Could not close zip file" (i am using a Windows Operating System)

Yii::getAlias('#web') returns URL of web application but for saving a file you need path of web application so try \Yii::getAlias('#webroot') instead.

Related

File upload in codeigniter in shortcut folder

This is not the first time I am doing file upload using CI. However in this particular case I want to upload images or files to shortcut folder created at project root. This is what my project root looks like in following image:
So basically what I had been trying to do is using php filesystem function is_dir('goku') (goku is shortcut folder as shown in above image that links to C:\Users\Name\Desktop) and if true then create a sub-folder inside it and insert the image or file in that sub-folder. However I didn't find any way to make the shortcut folder recognize as directory and returns file upload error -The upload path does not appear to be valid. Upload works fine on other folder. I know that php is not recognizing the shortcut folder as directory because on running is_dir('goku') returns false. I have gone through all probable solutions but now again back to where I started. Any helpful hints regarding this is highly appreciated. Thank You!!!
Using the library Codeigniter
library upload single file and multi file
Easily upload .

Excel 97 formatting issue on https centos laravel 5.0

I have a rather peculiar issue which appears to be related to excel formatting.
I have a Laravel 5.0 application and there's an Excel 97 (xlsx) download function using maatwebsite excel wrapper which works fine on my local MAMP platform as well on my CentOS VPS using a demo sub-domain on http:// connection.
But when I deployed the application to another folder and set it up to be served up by another subdomain on https:// connection on the same VPS, I get this error:
Excel cannot open this file.
The file format or file extension is not valid.
Verify that the file has not been corrupted and
that file extension matches the format of the file.
Any ideas what could be wrong?
Please note that exactly the same code works on the same server in a different folder under a different sub-domain on http:// protocol.
I even tried to create a basic file to eliminate data related issues but still get the same error, here's the test code I used:
Excel::create('Filename', function($excel) {
$excel->setTitle('Our new awesome title');
$excel->setCreator('Maatwebsite')
->setCompany('Maatwebsite');
$excel->setDescription('A demonstration to change the file properties');
})->export('xlsx');

I can't view the uploaded files in laravel

I have built an application using laravel that uploads pdf files to the public/pdfs/books/ folder. Then I am trying to create a pop up window that will display the uploaded file using the url.Bit while trying to view the file using my pop up box I am getting the following error.
Not allowed to load local resource: file:///C:/laragon/www/Uploader/public/pdfs/books/book.pdf
Can anyone suggest why I am getting this error? I even tried to load the file from another directory outside the application and got the same error. How Can I view the file from my application uploaded to folder
You shouldn't use the folder url like this. Because your application is running in local server So it should be able to view the file that starts with http.
To make the link for view use the following code in blade:
{{URL:to('/').'pdfs/abstracts/fillename.pdf'}}
Or use similar type of mechanism so the file is loaded with http protocol instead of from local directory starting with file:///C:
Can you view the file from browser?
file:///C:/laragon/www/Uploader/public/pdfs/books/book.pdf
If not, you should recheck your upload code.
Looks like permission issue, try chmod 775 -R * command in your /Uploader/public/pdfs directory. You could also try changing file permission in cpanel

PHP not detecting XLS file as zip

I am using a library to read XLS files which internally uses PHP's zip_open() function. When creating the files locally and then uploading to my test server everything works fine. However, when I use the XLS files downloaded from a website (normal download via browser), it does not work, instead returning Error 19 meaning that the file is not seen as a zip file, which is incorrect. Excel opens the file without problems. If I re-save the file locally as an XLSX file and then upload it, I get the same error (in this instance the file is opened by the PHP's ZipArchive class). Any ideas what the reason could be? I checked that the files are not read only, possibly some Unix permissions could be set that are not displayed in Windows? (Doubt this, as the error code indicates that the file could be accessed, but could not be identified as XLS)
Using:
Apache under Windows (WAMP)
PHP 5.4.12
It seems I had misread a line of code, the zip check is only done to determine if the XLS file is an incorrectly named XLSX file. The problem with the XLS file is that it returns no sheets when parsing, I need to look into this still. I do not know why saving the XLS file as an XLSX file (using Excel) results in an incorrect ZIP archive though, but guessing it is related.

Dropbox api - Can you get a hook to a file in dropbox? - PHP

I am investigating dropbox possibilities for integration with another api.
Can you get a hook to a file in dropbox.. for example - a url to open up and resave the file with new content.
Can you also create files using the dropbox api if permission has previously been granted? Maybe .txt or .xls files etc.
I believe that dropbox uses a local folder to store files, then some sort of background daemon to monitor said folder for changes. If this is the case, you can simply make changes to files in that folder and the rest should be automatic.
Please correct me if I'm wrong.

Categories