Merge pull request #21666 from bb2a/NEW---FTP-function-mkdir
NEW - FTP Function mkdir
This commit is contained in:
commit
075ac8335c
@ -276,3 +276,32 @@ function dol_ftp_rmdir($connect_id, $file, $newsection)
|
||||
return @ftp_rmdir($connect_id, $newremotefileiso);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Remove FTP directory
|
||||
*
|
||||
* @param resource $connect_id Connection handler
|
||||
* @param string $newdir Dir create
|
||||
* @param string $newsection $newsection
|
||||
* @return result
|
||||
*/
|
||||
function dol_ftp_mkdir($connect_id, $newdir, $newsection)
|
||||
{
|
||||
|
||||
global $conf;
|
||||
|
||||
if (!empty($conf->global->FTP_CONNECT_WITH_SFTP)) {
|
||||
$newsection = ssh2_sftp_realpath($connect_id, ".").'/./'; // workaround for bug https://bugs.php.net/bug.php?id=64169
|
||||
}
|
||||
|
||||
// Remote file
|
||||
$newremotefileiso = $newsection.(preg_match('@[\\\/]$@', $newsection) ? '' : '/').$newdir;
|
||||
$newremotefileiso = utf8_decode($newremotefileiso);
|
||||
|
||||
if (!empty($conf->global->FTP_CONNECT_WITH_SFTP)) {
|
||||
return ssh2_sftp_mkdir($connect_id, $newremotefileiso, 0777);
|
||||
} else {
|
||||
return @ftp_mkdir($connect_id, $newremotefileiso);
|
||||
}
|
||||
}
|
||||
|
||||
@ -41,6 +41,7 @@ $result = restrictedArea($user, 'ftp', '');
|
||||
// Get parameters
|
||||
$action = GETPOST('action', 'aZ09');
|
||||
$section = GETPOST('section');
|
||||
$newfolder = GETPOST('newfolder');
|
||||
if (!$section) {
|
||||
$section = '/';
|
||||
}
|
||||
@ -141,11 +142,8 @@ if ($action == 'uploadfile') {
|
||||
$mesg = $resultarray['mesg'];
|
||||
}
|
||||
if ($conn_id && $ok && !$mesg) {
|
||||
// var_dump($_FILES['userfile']['name']);
|
||||
$nbfile = count($_FILES['userfile']['name']);
|
||||
$i = 0;
|
||||
for (; $i < $nbfile; $i++) {
|
||||
var_dump($i);
|
||||
for ($i = 0; $i < $nbfile; $i++) {
|
||||
$newsection = $newsectioniso;
|
||||
$fileupload = $_FILES['userfile']['name'][$i];
|
||||
$fileuploadpath = $_FILES['userfile']['tmp_name'][$i];
|
||||
@ -164,6 +162,30 @@ if ($action == 'uploadfile') {
|
||||
}
|
||||
}
|
||||
|
||||
if ($action == 'addfolder') {
|
||||
// set up a connection or die
|
||||
if (!$conn_id) {
|
||||
$newsectioniso = utf8_decode($section);
|
||||
$resultarray = dol_ftp_connect($ftp_server, $ftp_port, $ftp_user, $ftp_password, $newsectioniso, $ftp_passive);
|
||||
$conn_id = $resultarray['conn_id'];
|
||||
$ok = $resultarray['ok'];
|
||||
$mesg = $resultarray['mesg'];
|
||||
}
|
||||
if ($conn_id && $ok && !$mesg) {
|
||||
$result = dol_ftp_mkdir($conn_id, $newfolder, $newsectioniso);
|
||||
|
||||
if ($result) {
|
||||
setEventMessages($langs->trans("FileWasCreateFolder", $newfolder), null, 'mesgs');
|
||||
} else {
|
||||
dol_syslog("ftp/index.php ftp_delete", LOG_ERR);
|
||||
setEventMessages($langs->trans("FTPFailedToCreateFolder", $newfolder), null, 'errors');
|
||||
}
|
||||
$action = '';
|
||||
} else {
|
||||
dol_print_error('', $mesg);
|
||||
}
|
||||
}
|
||||
|
||||
// Action ajout d'un rep
|
||||
if ($action == 'add' && $user->rights->ftp->setup) {
|
||||
$ecmdir->ref = GETPOST("ref");
|
||||
@ -633,6 +655,16 @@ if (!function_exists('ftp_connect')) {
|
||||
print '<td></td>';
|
||||
print '<td align="center"><button type="submit" class="butAction" name="uploadfile" value="'.$langs->trans("Save").'">'.$langs->trans("Upload").'</button></td>';
|
||||
print '</form>';
|
||||
print load_fiche_titre($langs->trans("AddFolder"), null, null);
|
||||
print '<form enctype="multipart/form-data" action="'.$_SERVER["PHP_SELF"].'" method="post">';
|
||||
print '<input type="hidden" name="token" value="'.newToken().'">';
|
||||
print '<input type="hidden" name="numero_ftp" value="'.$numero_ftp.'">';
|
||||
print '<input type="hidden" name="section" value="'.$section.'">';
|
||||
print '<input type="hidden" name="action" value="addfolder">';
|
||||
print '<td><input type="text" class="flat" name="newfolder" multiple></td>';
|
||||
print '<td></td>';
|
||||
print '<td align="center"><button type="submit" class="butAction" name="addfolder" value="'.$langs->trans("Save").'">'.$langs->trans("AddFolder").'</button></td>';
|
||||
print '</form>';
|
||||
}
|
||||
} else {
|
||||
$foundsetup = false;
|
||||
|
||||
@ -328,3 +328,6 @@ FailedToGetFile=Failed to get files %s
|
||||
ErrorFTPNodisconnect=Error to disconnect FTP/SFTP server
|
||||
FileWasUpload=File <b>%s</b> was upload
|
||||
FTPFailedToUploadFile=Failed to upload file <b>%s</b>.
|
||||
AddFolder=Create folder
|
||||
FileWasCreateFolder=Folder <b>%s</b> was create
|
||||
FTPFailedToCreateFolder=Failed to create folder <b>%s</b>.
|
||||
|
||||
Loading…
Reference in New Issue
Block a user