-
Notifications
You must be signed in to change notification settings - Fork 173
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[media] Special characters issue (#7386)
Solves an issue when if using special characters (&, <, >, ") the file download fails and the name of the file appears incorrectly in the browse tab of the media module. The script removes the special characters from the sql data table media as well as from the file system.
- Loading branch information
1 parent
7c195a3
commit e7e3650
Showing
2 changed files
with
60 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
/** | ||
* This script is written to clean up the files with special characters from the media data table as well as clean up the | ||
* quotes appearing as %22 in the file names in the file system | ||
* | ||
* To use the script: php Cleanup_Special_Chars_Media.php | ||
* | ||
* | ||
* PHP Version 7 | ||
* | ||
* @category Main | ||
* @package Loris | ||
* @author Pierre PAC SOO <pierre.pacsoo@mcin.ca> | ||
* @license Loris license | ||
* @link https://www.github.com/aces/Loris-Trunk/ | ||
*/ | ||
|
||
require_once __DIR__."/../generic_includes.php"; | ||
$config = NDB_Config::singleton(); | ||
|
||
$media_path = $config->getSetting('mediaPath'); | ||
|
||
$data = $DB->pselect( | ||
"SELECT id, file_name | ||
FROM media", | ||
[] | ||
); | ||
|
||
foreach($data as $key => $file) { | ||
|
||
// fileNameURLencoded is needed for the step line 48 as the file name got rid of '"' and replaced it with %22 | ||
// urldecode will get rid of %22 and replace it correctly for it to be inserted into the table | ||
$fileNameURLencoded = htmlspecialchars_decode($file['file_name']); | ||
$fileName = urldecode($fileNameURLencoded); | ||
|
||
// update only if file name has been updated | ||
if($fileName !== $file['file_name']) { | ||
|
||
// change name in sql table media | ||
$DB->unsafeupdate( | ||
"media", | ||
[ | ||
"file_name" => $fileName | ||
], | ||
[ | ||
"id" => $file['id'] | ||
] | ||
); | ||
|
||
// update name in file system | ||
rename($media_path.$fileNameURLencoded, $media_path.$fileName); | ||
print("Old file name: " . $file['file_name'] . ". New file name: " . $fileName . "\n\n"); | ||
} | ||
} |