This forum is no longer open and is for reading/searching only.
Please use our new MachForm Community Forum instead.
MachForm Community Forums » MachForm 2
Removing the extra characters appended to an uploaded file on download
Started 15 years ago by neilo | 5 posts |
-
Dear Appnitro people,
When a the form is used to upload a file, it appends a string of (what appears to be) random characters to the file name. For instance, the file
'freedom from.mp3'
gets renamed
'element_3_36f8156c09d5133251dd578e252a1441-2-freedom from.mp3'
in the machform/data/form_x/files folder and in the database.
This means that when I create a download link for it (using the smart file script from http://www.zubrag.com/scripts/download.php) it downloads the file with that long, somewhat ungainly, file name.
I notice that when you use the download link from the sent email or the MachForm Form Manager Entries area, it will download with the original correct file name; however I do not want to allow users access to that area.
I would like to be able for users to download the files with the original filenames.
The download link on my site looks like:
<a href="download.php?f=<?php echo $row_Recordset1['element_3']; ?>">Download</a>
and you can see what I'm trying to do here: http://www.buffalogals.co.uk/Admin/fileshare.php
It works fine, except for the characters appended to the file name.
Any help would be much appreciated.
Posted 15 years ago # -
That random hash code is there for security reason.
To download it, your download script need to strip it.Try to edit your download.php file, search around line 166:
header("Pragma: public");
above that line, add this code:
$filename_only = $asfname; $file_1 = substr($filename_only,strpos($filename_only,'-')+1); $filename_only = substr($file_1,strpos($file_1,'-')+1); $header_file = (strstr($_SERVER['HTTP_USER_AGENT'], 'MSIE')) ? preg_replace('/\./', '%2e', $filename_only, substr_count($filename_only, '.') - 1) : $filename_only; $asfname = $header_file;
that should strip the hash code.
MachForm Founder
Posted 15 years ago # -
Wow - that is so brilliant - and quick. Many thanks.
Posted 15 years ago # -
Those tokens can't be removed completely, but it can be reduced.
From this one:'element_3_36f8156c09d5133251dd578e252a1441-2-freedom from.mp3'
to became this one:
'element_3_-2-freedom from.mp3'The reason for that code is to associate your file with the correct form submission and prevent duplicate file overwrite.
If we remove the code completely, people uploading the file using the same file name would overwrite the old file.
MachForm Founder
Posted 14 years ago #
Reply
You must log in to post.