CSV files are opening as a page - php

I am new to web development and I am facing an abnormal issue with the CSV files.
I have a link to download a CSV file:
Sample CSV file
On my local machine it gives a dialog box for the download - that is correct and that is what I want.
When I upload the same code to my web server, it opens the csv file as a web page in the same browser tab. That I don't want, I want a dialog box for the download option!
Can anyone tell me what I am doing wrong or What I need to do?

You can add the following line to your .htaccess. All the CSV files will be forced to download if opened.
AddType application/octet-stream csv
It will add the MIME header to all csv files, so browser will understand that it needs to download the file, not show it.

Related

how can i restrict a file being viewed or downloaded using url? i want same file to be downloaded using php script

I want to restrict a pdf file on my server from being viewed or downloaded. for example, when somebody types below url in browser and press enter.
http://example.com/pdf/sample-pdf1.pdf
the file should not be viewed or downloaded. instead, it should get redirected somewhere else or should display some error message
But, when i download the same file using php or html code, it should get downloaded
for example when i use below code in a php file, it should get downloaded.
[a href="http://example.com/pdf/sample-pdf1.pdf" download]Download[/a]
Insert .htaccess file inside pdf directory with content:
"Deny from all" -
That will not allow access that directory and files inside it via URL.

Is it possible to save a text file in mobile sd card or internal storage using PHP script

i have a website which is resposive and built mainly for mobile use, Now i want to save a text file to mobile either memory, But from what i have tried it directly saves the file in server. is there a way to save it in mobile memory or giving such patch that it can be saved outside the root directry?
$handle = fopen($backup_name,'w+');
fwrite($handle,$content);
fclose($handle);
echo 'done';
this is what i have checked so far, in pc i can store it any where but i need it to store in certain location of mobile
make .htaccess file inside your downloadable content folder and put below code, Then it will download instead of showing the code.
AddType application/octect-stream .txt
If it is a .txt file you should do like above. You can put any file type by it's extension.

Html2pdf error when downloading a pdf file in remote server

I'm using yii with html2pdf version 4.03 for downloading pdf documents in my project. The pdf documents consist of tables with many rows because they are reports. In my localhost, the download is fine. But when I do that in remote server, it can't be downloaded.
I used Firefox to download it. When I downloaded it, it prompted an alert message saying that I can't download because the source file cannot be read. When I force to download it (by pressing refresh button in firefox's download list), the pdf file is there. When I tried to open it, it says that the file is corrupted.
If I delete a few rows, it can be downloaded just fine. Strangely, even if I didn't delete the rows, they are still in one page. So the problem shouldn't be about "table row that doesn't fit in one page", should it?
What could be the problem? Could anyone help me with this please?
UPDATES
when I print it in browser instead of downloading, firefox prompts an error like below:
Content Encoding Error
The page you are trying to view cannot be shown because it uses an invalid or unsupported form of compression.
Please contact the website owners to inform them of this problem.
Still don't know how to solve this though...
Save the generated pdf, open it in text editor, and see what error message is there.

CSV File displayed by browser insteed of prompting download

In my application, it returns a csv file location on my server through an ajax call of a php page.
I want the browser to prompt for download. I use
location.href = "report.csv";
But when the code is executed in a browser, it opens the csv file by itself and is not prompting for download.
This problem occurs with my LAMP server whereas in my laptop, which is configured in XAMPP, the same code works fine and prompts for download.
I have found that some programmer refer to use content-dispose as header in the page.
But I think I have missed some configuration in httpd.conf file.
Does anyone have the solution?
Thanks in advance.
Tathagata
set location.href = a.php (as example). then set header content of that a.php file to csv type and then echo your csv file(see google help). Maybe this will help you. see header content for csv file for html page from google.

Flash/PHP: Using the AS3 Jpeg Encoder

I am a beginner at both Actionscript3 and PHP, and I'm trying to get Henry Jone's movie clip to jpeg code to work for me, as seen here:
http://henryjones.us/articles/using-the-as3-jpeg-encoder
I downloaded the source and then uploaded the .swf and the .php in the same directory. However, when I click "download your sketch," it downloads the .php file instead of a jpeg.
The .swf I uploaded can be seen here:
http://www.snut.org/storage/scrntest/sketch.swf
I didn't change any of the code from the source I downloaded, so I can't figure our what the problem is. Can anyone help?
Rule of thumb - any time your web server downloads .php files instead of rendering the output of the file it is a good sign that your server isn't set up to handle PHP. You need to tell Apache to use PHP, google around for "install PHP on Apache web server" and that should get you started.
Basically .php files are just text files, so unless you have something telling your web server to treat .php files different from normal text files then it'll just assume the user wants to download the file that's being linked.

Categories