简体   繁体   中英

What are possible reasons that HTML download link is failing?

I created a page for users to download certain files. I used the HTML download link to do this as so:

<a download href="/home/Uploads/someDir/someFile.PNG" >View</a>

This worked fine when I was developing on my laptop with WAMP. When I uploaded the code to our Centos 7 Server it did not work. I changed the Uploads, someDir, and someFile.PNG permissions to 777. I also made sure that the file path was correct. But the when the download link is pressed the file icon at the bottom of the screen says "Failed no file".

Maybe I need to do more with the permissions. I know that the folder that the html file is in has restricted permissions, but I would prefer to keep them that way. I do not know how that could cause an issue.

I am looking for debugging tips/possible causes. At this point I am clueless where to look.

The issue with the download not working is simply due to the fact that the path to your file is wrong. My advice on your root directory which is in most cases is var/www/html, create a folder called say somefoldername and manually upload the file to that folder then change the download link to be

<a href="somefoldername/someFile.PNG">View</a>.

"Failed no file" has nothing to do with permissions. The path to your download file has most likely changed when the files were uploaded to the server. You should manually check to see if the file at

/home/Uploads/someDir/someFile.PNG

actually exists. If not you can change the link accordingly or move the download file to the appropriate location.

Another good alternative to solve this error is to put a dot '.' at the beginning of the url:

<a download href="./someDir/someFile.PNG" >View</a>

This way you will not need to indicate the complete url. And if in the future the url changes, you won't have to modify the url. In my case it works perfect, I hope it helps you too.

Just check the directory in which you are trying to fetch the file. Your looking file may be not present in that directory. Otherwise, you are using the correct piece of code.

<a download href="~/home/Uploads/someDir/someFile.PNG" >View</a>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM