dongluan7821 2019-04-23 15:47
浏览 607

如何创建URL以使用HTML和PHP自动下载文件?

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?

  • 写回答

2条回答 默认 最新

  • doo58088 2019-04-23 15:57
    关注

    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.

    评论

报告相同问题?

悬赏问题

  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 正弦信号发生器串并联电路电阻无法保持同步怎么办
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 个人网站被恶意大量访问,怎么办
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)