My problem:
I wanna be able to send to my costumers a link like mywebsite.com/products
so they can download a .xlsx
file and see what I'm seeling atm.
Is there any way to create a link like "www.mywebsite.com/file
" so when the user access this URL the browser will open a prompt to download a .xlsx
file?
Here's my products.html
file:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Refresh" content="0; url=http://mywebsite.com/products.xlsx"/>
</head>
</html>
I've already uploaded the products.xlsx
to my server.
I've noted that if I access the website using the extension .html
, it prompt's the user to download the file. If I access without the extension, it leads me to a 404 error.
Maybe it's my .htaccess
config that is causing this?
Maybe the Options +MultiViews
or the HTML RewriteCond
..
Options All -Indexes
DirectoryIndex index.php index.htm index.html
RewriteEngine on
RewriteBase /
# ---- Make pages render without their extension in the url
Options +MultiViews
# Force HTTPS on the subdomains/subdirectories login or admin
#RewriteCond %{HTTPS} off
#RewriteCond %{HTTP_HOST} ^(login|admin)\. [NC]
#RewriteCond %{REQUEST_URI} ^(login|admin)\. [NC,OR]
#RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
# Force WWW if no subdomain is given
RewriteCond %{HTTP_HOST} ^[^.]+\.[^.]+$
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
# Remove php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
# Remove html
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.html [NC,L]
How can I fix this?
dot.Py do you want the link to the products.xlsx file to change depending on who it is you're speaking to? Ie. one client may have a particular products.xlsx file containing some information but another might have completely different information that they need to see.
If that's not the case, you can use an <a>
tag to reference the link.
So for example:
<a href='/excel/products.xlsx' target="_blank">Click to Download Excel Document</a>
Then all you'd need to do is include that within your <body>
on the page and clients could click the link to download the file.
If you want to use PHP to serve a xlsx file upon loading the webpage :
<?php
$fileName = 'Products.xlsx';
$filePath = "[PATH]/products.xlsx";
header('Content-disposition: attachment; filename=' . $fileName);
header('Content-type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Length: ' . filesize($filePath));
header('Content-Transfer-Encoding: binary');
header('Cache-Control: must-revalidate');
header('Pragma: public');
readfile($filePath);
Replace the [PATH] with your file path.