mirror of
https://github.com/Karaka-Management/phpOMS.git
synced 2026-02-05 20:18:42 +00:00
fix ftp upload
This commit is contained in:
parent
5e63303b67
commit
12b8eea76c
|
|
@ -125,6 +125,7 @@ class File extends FileAbstract implements FileInterface
|
||||||
{
|
{
|
||||||
$exists = self::exists($con, $path);
|
$exists = self::exists($con, $path);
|
||||||
|
|
||||||
|
// @todo: consider to use the php://memory way, used in the seUpBeforeClass in the test
|
||||||
if ((ContentPutMode::hasFlag($mode, ContentPutMode::APPEND) && $exists)
|
if ((ContentPutMode::hasFlag($mode, ContentPutMode::APPEND) && $exists)
|
||||||
|| (ContentPutMode::hasFlag($mode, ContentPutMode::PREPEND) && $exists)
|
|| (ContentPutMode::hasFlag($mode, ContentPutMode::PREPEND) && $exists)
|
||||||
|| (ContentPutMode::hasFlag($mode, ContentPutMode::REPLACE) && $exists)
|
|| (ContentPutMode::hasFlag($mode, ContentPutMode::REPLACE) && $exists)
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,34 @@ final class DirectoryTest extends \PHPUnit\Framework\TestCase
|
||||||
public static function setUpBeforeClass() : void
|
public static function setUpBeforeClass() : void
|
||||||
{
|
{
|
||||||
self::$con = Directory::ftpConnect(new HttpUri(self::BASE));
|
self::$con = Directory::ftpConnect(new HttpUri(self::BASE));
|
||||||
|
|
||||||
|
if (self::$con === false) {
|
||||||
|
self::$con = null;
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
$mkdir = \ftp_mkdir(self::$con, '0xFF');
|
||||||
|
\ftp_rmdir(self::$con, '0xFF');
|
||||||
|
|
||||||
|
$f = \fopen('php://memory', 'r+');
|
||||||
|
\fwrite($f, '0x00');
|
||||||
|
\rewind($f);
|
||||||
|
|
||||||
|
$put = \ftp_fput(self::$con, '0x00', $f);
|
||||||
|
\fclose($f);
|
||||||
|
|
||||||
|
\ftp_delete(self::$con, '0x00');
|
||||||
|
|
||||||
|
if (!$mkdir || !$put) {
|
||||||
|
throw new \Exception();
|
||||||
|
}
|
||||||
|
} catch (\Throwable $t) {
|
||||||
|
self::$con = null;
|
||||||
|
|
||||||
|
var_dump($t->getMessage());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -38,26 +66,10 @@ final class DirectoryTest extends \PHPUnit\Framework\TestCase
|
||||||
*/
|
*/
|
||||||
protected function setUp() : void
|
protected function setUp() : void
|
||||||
{
|
{
|
||||||
if (self::$con === false) {
|
if (self::$con === null) {
|
||||||
$this->markTestSkipped(
|
$this->markTestSkipped(
|
||||||
'The ftp connection is not available.'
|
'The ftp connection is not available.'
|
||||||
);
|
);
|
||||||
} else {
|
|
||||||
try {
|
|
||||||
$mkdir = \ftp_mkdir(self::$con, '0xFF');
|
|
||||||
\ftp_rmdir(self::$con, '0xFF');
|
|
||||||
|
|
||||||
$put = \ftp_put(self::$con, '0x00');
|
|
||||||
\ftp_delete(self::$con, '0x00');
|
|
||||||
|
|
||||||
if (!$mkdir || !$put) {
|
|
||||||
throw new \Exception();
|
|
||||||
}
|
|
||||||
} catch (\Throwable $t) {
|
|
||||||
$this->markTestSkipped(
|
|
||||||
'No write permissions on ftp server.'
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -894,7 +906,7 @@ final class DirectoryTest extends \PHPUnit\Framework\TestCase
|
||||||
public function testNodeInvalid() : void
|
public function testNodeInvalid() : void
|
||||||
{
|
{
|
||||||
$dir = new Directory(new HttpUri(self::BASE . __DIR__ . '/dirtest'), '*', true, self::$con);
|
$dir = new Directory(new HttpUri(self::BASE . __DIR__ . '/dirtest'), '*', true, self::$con);
|
||||||
$dir->next()->next()->next()->next()->next()->next()->next();
|
$dir?->next()?->next()?->next()?->next()?->next()?->next()?->next();
|
||||||
|
|
||||||
self::assertFalse($dir->valid());
|
self::assertFalse($dir->valid());
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -33,6 +33,32 @@ final class FileTest extends \PHPUnit\Framework\TestCase
|
||||||
public static function setUpBeforeClass() : void
|
public static function setUpBeforeClass() : void
|
||||||
{
|
{
|
||||||
self::$con = File::ftpConnect(new HttpUri(self::BASE));
|
self::$con = File::ftpConnect(new HttpUri(self::BASE));
|
||||||
|
|
||||||
|
if (self::$con === false) {
|
||||||
|
self::$con = null;
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
$mkdir = \ftp_mkdir(self::$con, '0xFF');
|
||||||
|
\ftp_rmdir(self::$con, '0xFF');
|
||||||
|
|
||||||
|
$f = \fopen('php://memory', 'r+');
|
||||||
|
\fwrite($f, '0x00');
|
||||||
|
\rewind($f);
|
||||||
|
|
||||||
|
$put = \ftp_fput(self::$con, '0x00', $f);
|
||||||
|
\fclose($f);
|
||||||
|
|
||||||
|
\ftp_delete(self::$con, '0x00');
|
||||||
|
|
||||||
|
if (!$mkdir || !$put) {
|
||||||
|
throw new \Exception();
|
||||||
|
}
|
||||||
|
} catch (\Throwable $t) {
|
||||||
|
self::$con = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -40,26 +66,10 @@ final class FileTest extends \PHPUnit\Framework\TestCase
|
||||||
*/
|
*/
|
||||||
protected function setUp() : void
|
protected function setUp() : void
|
||||||
{
|
{
|
||||||
if (self::$con === false) {
|
if (self::$con === null) {
|
||||||
$this->markTestSkipped(
|
$this->markTestSkipped(
|
||||||
'The ftp connection is not available.'
|
'The ftp connection is not available.'
|
||||||
);
|
);
|
||||||
} else {
|
|
||||||
try {
|
|
||||||
$mkdir = \ftp_mkdir(self::$con, '0xFF');
|
|
||||||
\ftp_rmdir(self::$con, '0xFF');
|
|
||||||
|
|
||||||
$put = \ftp_put(self::$con, '0x00');
|
|
||||||
\ftp_delete(self::$con, '0x00');
|
|
||||||
|
|
||||||
if (!$mkdir || !$put) {
|
|
||||||
throw new \Exception();
|
|
||||||
}
|
|
||||||
} catch (\Throwable $t) {
|
|
||||||
$this->markTestSkipped(
|
|
||||||
'No write permissions on ftp server.'
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -34,6 +34,34 @@ final class FtpStorageTest extends \PHPUnit\Framework\TestCase
|
||||||
public static function setUpBeforeClass() : void
|
public static function setUpBeforeClass() : void
|
||||||
{
|
{
|
||||||
self::$con = Directory::ftpConnect(new HttpUri(self::BASE));
|
self::$con = Directory::ftpConnect(new HttpUri(self::BASE));
|
||||||
|
|
||||||
|
if (self::$con === false) {
|
||||||
|
self::$con = null;
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
$mkdir = \ftp_mkdir(self::$con, '0xFF');
|
||||||
|
\ftp_rmdir(self::$con, '0xFF');
|
||||||
|
|
||||||
|
$f = \fopen('php://memory', 'r+');
|
||||||
|
\fwrite($f, '0x00');
|
||||||
|
\rewind($f);
|
||||||
|
|
||||||
|
$put = \ftp_fput(self::$con, '0x00', $f);
|
||||||
|
\fclose($f);
|
||||||
|
|
||||||
|
\ftp_delete(self::$con, '0x00');
|
||||||
|
|
||||||
|
if (!$mkdir || !$put) {
|
||||||
|
throw new \Exception();
|
||||||
|
}
|
||||||
|
} catch (\Throwable $t) {
|
||||||
|
self::$con = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
FtpStorage::with(self::$con);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -41,29 +69,11 @@ final class FtpStorageTest extends \PHPUnit\Framework\TestCase
|
||||||
*/
|
*/
|
||||||
protected function setUp() : void
|
protected function setUp() : void
|
||||||
{
|
{
|
||||||
if (self::$con === false) {
|
if (self::$con === null) {
|
||||||
$this->markTestSkipped(
|
$this->markTestSkipped(
|
||||||
'The ftp connection is not available.'
|
'The ftp connection is not available.'
|
||||||
);
|
);
|
||||||
} else {
|
|
||||||
try {
|
|
||||||
$mkdir = \ftp_mkdir(self::$con, '0xFF');
|
|
||||||
\ftp_rmdir(self::$con, '0xFF');
|
|
||||||
|
|
||||||
$put = \ftp_put(self::$con, '0x00');
|
|
||||||
\ftp_delete(self::$con, '0x00');
|
|
||||||
|
|
||||||
if (!$mkdir || !$put) {
|
|
||||||
throw new \Exception();
|
|
||||||
}
|
|
||||||
} catch (\Throwable $t) {
|
|
||||||
$this->markTestSkipped(
|
|
||||||
'No write permissions on ftp server.'
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
FtpStorage::with(self::$con);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user