FIX Upload in the filemanager use the Dolibarr methods
This commit is contained in:
parent
2d93c6b678
commit
c7bb6c3c4c
@ -65,6 +65,7 @@ function SetCurrentFolder( resourceType, folderPath )
|
|||||||
|
|
||||||
function OnSubmit()
|
function OnSubmit()
|
||||||
{
|
{
|
||||||
|
console.log("Click on OnSubmit");
|
||||||
if ( document.getElementById('NewFile').value.length == 0 )
|
if ( document.getElementById('NewFile').value.length == 0 )
|
||||||
{
|
{
|
||||||
alert( 'Please select a file from your computer' );
|
alert( 'Please select a file from your computer' );
|
||||||
@ -80,6 +81,8 @@ function OnSubmit()
|
|||||||
|
|
||||||
function OnUploadCompleted( errorNumber, data )
|
function OnUploadCompleted( errorNumber, data )
|
||||||
{
|
{
|
||||||
|
console.log("errorNumber = "+errorNumber);
|
||||||
|
|
||||||
// Reset the Upload Worker Frame.
|
// Reset the Upload Worker Frame.
|
||||||
window.parent.frames['frmUploadWorker'].location = 'javascript:void(0)' ;
|
window.parent.frames['frmUploadWorker'].location = 'javascript:void(0)' ;
|
||||||
|
|
||||||
@ -106,7 +109,7 @@ function OnUploadCompleted( errorNumber, data )
|
|||||||
alert( 'A file with the same name is already available. The uploaded file has been renamed to "' + data + '"' );
|
alert( 'A file with the same name is already available. The uploaded file has been renamed to "' + data + '"' );
|
||||||
break;
|
break;
|
||||||
case 202:
|
case 202:
|
||||||
alert( 'Invalid file' );
|
alert( 'Invalid file (Bad extension)' );
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
alert( 'Error on file upload. Error number: ' + errorNumber );
|
alert( 'Error on file upload. Error number: ' + errorNumber );
|
||||||
|
|||||||
@ -203,12 +203,17 @@ function FileUpload($resourceType, $currentFolder, $sCommand, $CKEcallback = '')
|
|||||||
|
|
||||||
$oFile = isset($_FILES['NewFile']) ? $_FILES['NewFile'] : $_FILES['upload'];
|
$oFile = isset($_FILES['NewFile']) ? $_FILES['NewFile'] : $_FILES['upload'];
|
||||||
|
|
||||||
|
// $resourceType should be 'Image';
|
||||||
|
$detectHtml = 0;
|
||||||
|
|
||||||
// Map the virtual path to the local server path.
|
// Map the virtual path to the local server path.
|
||||||
$sServerDir = ServerMapFolder($resourceType, $currentFolder, $sCommand);
|
$sServerDir = ServerMapFolder($resourceType, $currentFolder, $sCommand);
|
||||||
|
|
||||||
// Get the uploaded file name.
|
// Get the uploaded file name.
|
||||||
$sFileName = $oFile['name'];
|
$sFileName = $oFile['name'];
|
||||||
$sFileName = SanitizeFileName($sFileName);
|
|
||||||
|
//$sFileName = SanitizeFileName($sFileName);
|
||||||
|
$sFileName = dol_sanitizeFileName($sFileName);
|
||||||
|
|
||||||
$sOriginalFileName = $sFileName;
|
$sOriginalFileName = $sFileName;
|
||||||
|
|
||||||
@ -216,6 +221,8 @@ function FileUpload($resourceType, $currentFolder, $sCommand, $CKEcallback = '')
|
|||||||
$sExtension = substr($sFileName, (strrpos($sFileName, '.') + 1));
|
$sExtension = substr($sFileName, (strrpos($sFileName, '.') + 1));
|
||||||
$sExtension = strtolower($sExtension);
|
$sExtension = strtolower($sExtension);
|
||||||
|
|
||||||
|
//var_dump($Config);
|
||||||
|
/*
|
||||||
if (isset($Config['SecureImageUploads'])) {
|
if (isset($Config['SecureImageUploads'])) {
|
||||||
if (($isImageValid = IsImageValid($oFile['tmp_name'], $sExtension)) === false) {
|
if (($isImageValid = IsImageValid($oFile['tmp_name'], $sExtension)) === false) {
|
||||||
$sErrorNumber = '202';
|
$sErrorNumber = '202';
|
||||||
@ -228,6 +235,14 @@ function FileUpload($resourceType, $currentFolder, $sCommand, $CKEcallback = '')
|
|||||||
$sErrorNumber = '202';
|
$sErrorNumber = '202';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
include_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
|
||||||
|
$isImageValid = image_format_supported($sFileName) > 0 ? true : false;
|
||||||
|
if (!$isImageValid) {
|
||||||
|
$sErrorNumber = '202';
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Check if it is an allowed extension.
|
// Check if it is an allowed extension.
|
||||||
if (!$sErrorNumber && IsAllowedExt($sExtension, $resourceType)) {
|
if (!$sErrorNumber && IsAllowedExt($sExtension, $resourceType)) {
|
||||||
@ -241,7 +256,8 @@ function FileUpload($resourceType, $currentFolder, $sCommand, $CKEcallback = '')
|
|||||||
$sFileName = RemoveExtension($sOriginalFileName).'('.$iCounter.').'.$sExtension;
|
$sFileName = RemoveExtension($sOriginalFileName).'('.$iCounter.').'.$sExtension;
|
||||||
$sErrorNumber = '201';
|
$sErrorNumber = '201';
|
||||||
} else {
|
} else {
|
||||||
move_uploaded_file($oFile['tmp_name'], $sFilePath);
|
include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
|
||||||
|
dol_move_uploaded_file($oFile['tmp_name'], $sFilePath, 0, 0);
|
||||||
|
|
||||||
if (is_file($sFilePath)) {
|
if (is_file($sFilePath)) {
|
||||||
if (isset($Config['ChmodOnUpload']) && !$Config['ChmodOnUpload']) {
|
if (isset($Config['ChmodOnUpload']) && !$Config['ChmodOnUpload']) {
|
||||||
|
|||||||
@ -408,6 +408,7 @@ EOF;
|
|||||||
}
|
}
|
||||||
|
|
||||||
$rpl = array('\\' => '\\\\', '"' => '\\"');
|
$rpl = array('\\' => '\\\\', '"' => '\\"');
|
||||||
|
echo 'console.log('.$errorNumber.');';
|
||||||
echo 'window.parent.OnUploadCompleted('.$errorNumber.', "'.strtr($fileUrl, $rpl).'", "'.strtr($fileName, $rpl).'", "'.strtr($customMsg, $rpl).'");';
|
echo 'window.parent.OnUploadCompleted('.$errorNumber.', "'.strtr($fileUrl, $rpl).'", "'.strtr($fileName, $rpl).'", "'.strtr($customMsg, $rpl).'");';
|
||||||
echo '</script>';
|
echo '</script>';
|
||||||
exit;
|
exit;
|
||||||
|
|||||||
@ -22,11 +22,12 @@
|
|||||||
* This is the "File Uploader" for PHP.
|
* This is the "File Uploader" for PHP.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
require 'config.php';
|
require 'config.php'; // This include the main.inc.php
|
||||||
require 'util.php';
|
require 'util.php';
|
||||||
require 'io.php';
|
require 'io.php';
|
||||||
require 'commands.php';
|
require 'commands.php';
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SendError
|
* SendError
|
||||||
*
|
*
|
||||||
@ -63,6 +64,7 @@ if (!IsAllowedType($sType)) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// @CHANGE
|
// @CHANGE
|
||||||
//FileUpload( $sType, $sCurrentFolder, $sCommand )
|
//FileUpload( $sType, $sCurrentFolder, $sCommand )
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user