I'm wondering if this can be done with PHP. Here's the problem:
On the server are a number of files with eight character filenames and ??? extensions, where ??? is a number from 001 to 999. So the file could be thisfile.074, for example
Can I have a simple text box on screen where this information can be entered, and when the submit button is clicked, the file is written to the hard drive in a pre-dertermined location.
Or is that not possible? If not, any ideas?
Downloading files and avoiding .txt extension
Moderator: General Moderators
try
Code: Select all
header('Content-type: application/octet-stream');
header('Content-disposition: attachment; filename='.$filename);somehow the browser must be under the impression that the document has the mime-type text/plain or text/html. Is it IE?
If there's no way to let your webserver perform the task maybe you can circumvent this behaviour by redirecting the link via a php-script.that's the very basics.
If there's no way to let your webserver perform the task maybe you can circumvent this behaviour by redirecting the link via a php-script.
Code: Select all
<a href="getFile.php?file=thisfile.074">thisfile.074</a>Code: Select all
// some code that tests the userinput ("file" set AND valid?)
header('Content-type: application/octet-stream');
header('Content-disposition: attachment; filename='.$_GETїfilename]);
readfile($_GETїfilename]);- todo
- validation, security issues
- get rid of directories in filename='.$_GET[filename]
- content-length header
Thanks again volka - I thought there may have been an easy solution but I see this isn't something for a newcomer to PHP so I'll need to spend some time working it out (I understand your stance on 'post-me-a-script' but I didn't realise it would be so involved).
Yes, it is IE & NetScape and ideally different file names with a fixed .txt extension should be used so the number that is now used as an extension isn't lost (which is vital) but that isn't an option so I'm just trying to find a quick way around someone else's bad system. I was hoping I could set the download path beforehand and when the link is clicked the file would be saved automatically, without the usual 'Save As' box appearing...
Yes, it is IE & NetScape and ideally different file names with a fixed .txt extension should be used so the number that is now used as an extension isn't lost (which is vital) but that isn't an option so I'm just trying to find a quick way around someone else's bad system. I was hoping I could set the download path beforehand and when the link is clicked the file would be saved automatically, without the usual 'Save As' box appearing...