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
Renaming Files on Upload
Started 15 years ago by BFG9000 | 2 posts |
-
Greetings All,
I have a form that includes a couple of file uploads (one for .jpg & one for .pdf).
Another field on the form is for A unique identifier that the user keys in (e.g. GT5000123456).I'd like the files to be renamed on upload to GT5000123456.jpg & GT5000123456.pdf respectively.
I'm fairly sure this is possible, but I guess I'm lloking for some assistance.....
TTFN
BFG
Posted 15 years ago # -
Hi,
Hmmm ... I think it will be take a lot of modification, you should edit some machform files then. Let's follow these steps :
1. Edit "includes/post-functions.php". go to around line 1029 ~ 1035 you will see this code :
//move file and check for invalid file $destination_file = $input['machform_data_path'].UPLOAD_DIR."/form_{$form_id}/files/{$element_name}_{$file_token}-{$record_insert_id}-{$_FILES[$element_name]['name']}"; if (move_uploaded_file($_FILES[$element_name]['tmp_name'], $destination_file)) { $filename = mysql_real_escape_string($_FILES[$element_name]['name']); $query = "update ap_form_{$form_id} set $element_name='{$element_name}_{$file_token}-{$record_insert_id}-{$filename}' where id='$record_insert_id'"; do_query($query); }
replace with this
if ($form_id != 25) { //move file and check for invalid file $destination_file = $input['machform_data_path'].UPLOAD_DIR."/form_{$form_id}/files/{$element_name}_{$file_token}-{$record_insert_id}-{$_FILES[$element_name]['name']}"; if (move_uploaded_file($_FILES[$element_name]['tmp_name'], $destination_file)) { $filename = mysql_real_escape_string($_FILES[$element_name]['name']); $query = "update ap_form_{$form_id} set $element_name='{$element_name}_{$file_token}-{$record_insert_id}-{$filename}' where id='$record_insert_id'"; do_query($query); }
2. Edit "download.php" file, go to around line 33. You will see this code :
$file_1 = substr($filename_only,strpos($filename_only,'-')+1); $filename_only = substr($file_1,strpos($file_1,'-')+1);
replace with
if ($form_id == 25) { $file_1 = $filename_only; $filename_only = $file_1; }else { $file_1 = substr($filename_only,strpos($filename_only,'-')+1); $filename_only = substr($file_1,strpos($file_1,'-')+1); }
3. Edit "includes/helper-functions.php", go to around line 383 and you will see this code :
$filename_value = substr($filename_value,strpos($filename_value,'-')+1); $filename_value = substr($file_1,strpos($file_1,'-')+1);
replace with
if ($form_id == 25) { $file_1 = $filename_value; $filename_only = $file_1; }else { $filename_value = substr($filename_value,strpos($filename_value,'-')+1); $filename_value = substr($file_1,strpos($file_1,'-')+1); }
I assume your form id is 25, so make sure you've adjust your form id with yours.
MachForm Support
Posted 15 years ago #
Reply
You must log in to post.