A relative URL (neither a complete URL, i.e. one that starts with a protocol like http://
nor one that starts with a /
indicating the root of the site) is relative to the last /
in the URL. This means that if you have <a href="code.txt">Code</a>
on http://www.example.com/dir/page.html
then page.html
is dropped and code.txt
is appended, leading to http://www.example.com/dir/code.txt
. If the code.txt
file is not uploaded to that location on your webserver, it will not be found.
Are you sure code.txt
is live on the server? That is to say can you navigate manually to the text file on your server?
Are you sure your PHP file is in the same directory as code.txt
?
Are there any case (upper/lowercase) issues, like @BugFinder mentioned?
Does it work without the JavaScript popup? From your question it doesn't sound like a JS issue, but seeing as @Sathish thought there was something to correct with your popup behavior (it looks fine to me) it's worth removing that variable and seeing if a plain link works.
Are there any permission issues or restrictions on your server preventing the file from being displayed? For that matter, what is the exact error code and message you are receiving? 404? Something else?
I'm inclined to guess from what you've said so far that the file hasn't actually been uploaded. Alternatively, it's not actually in the same directory as your PHP file, despite what you've said. If it's neither of these issues, please update your question with more details.
If the file exists according to FTP, there's a couple of possibilities:
- The file is on the server, but not where you think it is. For example, many webhosts have a private root directory that is not accessible to the web, inside of which is a
public_html/
or www/
directory which is the actual root of your website. Have you been able to upload other files to your website in the past? It sounds like the PHP file is successfully available, so assuming the txt file's in the same place, this isn't the issue.
- Your website is not set to allow .txt files to be served up to browsers. Have you been able to upload and see any txt files, or is this the first file with this problem? What happens if, for the sake of trying it, you rename the file to
code.html
and upload that to the same place?
For the record, this is likely a far better question to bring up with your host (or just look through their docs / support) than with StackOverflow, it's not a programming question but a hosting issue. Since we don't know who your host is, nor the intricacies of every individual hosting provider, it's hard to diagnose what's wrong.