添加网站文件

This commit is contained in:
2025-12-22 13:59:40 +08:00
commit 117aaf83d1
19468 changed files with 2111999 additions and 0 deletions

View File

@@ -0,0 +1,71 @@
<?php
// Hack to override the time returned from the S3SignatureV4
// @codingStandardsIgnoreStart
namespace Qiniu {
function time()
{
return isset($_SERVER['override_qiniu_auth_time'])
? 1234567890
: \time();
}
}
namespace Qiniu\Tests {
use Qiniu\Auth;
// @codingStandardsIgnoreEnd
class AuthTest extends \PHPUnit_Framework_TestCase
{
public function testSign()
{
global $dummyAuth;
$token = $dummyAuth->sign('test');
$this->assertEquals('abcdefghklmnopq:mSNBTR7uS2crJsyFr2Amwv1LaYg=', $token);
}
public function testSignWithData()
{
global $dummyAuth;
$token = $dummyAuth->signWithData('test');
$this->assertEquals('abcdefghklmnopq:-jP8eEV9v48MkYiBGs81aDxl60E=:dGVzdA==', $token);
}
public function testSignRequest()
{
global $dummyAuth;
$token = $dummyAuth->signRequest('http://www.qiniu.com?go=1', 'test', '');
$this->assertEquals('abcdefghklmnopq:cFyRVoWrE3IugPIMP5YJFTO-O-Y=', $token);
$ctype = 'application/x-www-form-urlencoded';
$token = $dummyAuth->signRequest('http://www.qiniu.com?go=1', 'test', $ctype);
$this->assertEquals($token, 'abcdefghklmnopq:svWRNcacOE-YMsc70nuIYdaa1e4=');
}
public function testPrivateDownloadUrl()
{
global $dummyAuth;
$_SERVER['override_qiniu_auth_time'] = true;
$url = $dummyAuth->privateDownloadUrl('http://www.qiniu.com?go=1');
$expect = 'http://www.qiniu.com?go=1&e=1234571490&token=abcdefghklmnopq:8vzBeLZ9W3E4kbBLFLW0Xe0u7v4=';
$this->assertEquals($expect, $url);
unset($_SERVER['override_qiniu_auth_time']);
}
public function testUploadToken()
{
global $dummyAuth;
$_SERVER['override_qiniu_auth_time'] = true;
$token = $dummyAuth->uploadToken('1', '2', 3600, array('endUser' => 'y'));
// @codingStandardsIgnoreStart
$exp = 'abcdefghklmnopq:yyeexeUkPOROoTGvwBjJ0F0VLEo=:eyJlbmRVc2VyIjoieSIsInNjb3BlIjoiMToyIiwiZGVhZGxpbmUiOjEyMzQ1NzE0OTB9';
// @codingStandardsIgnoreEnd
$this->assertEquals($exp, $token);
unset($_SERVER['override_qiniu_auth_time']);
}
public function testVerifyCallback()
{
}
}
}

View File

@@ -0,0 +1,14 @@
<?php
namespace Qiniu\Tests;
use Qiniu;
class Base64Test extends \PHPUnit_Framework_TestCase
{
public function testUrlSafe()
{
$a = '你好';
$b = \Qiniu\base64_urlSafeEncode($a);
$this->assertEquals($a, \Qiniu\base64_urlSafeDecode($b));
}
}

View File

@@ -0,0 +1,451 @@
<?php
namespace Qiniu\Tests;
use Qiniu\Config;
use Qiniu\Storage\BucketManager;
class BucketTest extends \PHPUnit_Framework_TestCase
{
protected $bucketManager;
protected $dummyBucketManager;
protected $bucketName;
protected $key;
protected $key2;
protected $customCallbackURL;
protected function setUp()
{
global $bucketName;
global $key;
global $key2;
$this->bucketName = $bucketName;
$this->key = $key;
$this->key2 = $key2;
global $customCallbackURL;
$this->customCallbackURL = $customCallbackURL;
global $testAuth;
$config = new Config();
$this->bucketManager = new BucketManager($testAuth, $config);
global $dummyAuth;
$this->dummyBucketManager = new BucketManager($dummyAuth);
}
public function testBuckets()
{
list($list, $error) = $this->bucketManager->buckets();
$this->assertTrue(in_array($this->bucketName, $list));
$this->assertNull($error);
list($list2, $error) = $this->dummyBucketManager->buckets();
$this->assertEquals(401, $error->code());
$this->assertNull($list2);
$this->assertNotNull($error->message());
$this->assertNotNull($error->getResponse());
}
public function testListbuckets()
{
list($ret, $error) = $this->bucketManager->listbuckets('z0');
$this->assertNotNull($ret);
$this->assertNull($error);
}
public function testCreateBucket()
{
list($ret, $error) = $this->bucketManager->createBucket('phpsdk-ci-test');
$this->assertNotNull($ret);
$this->assertNull($error);
}
public function testDeleteBucket()
{
list($ret, $error) = $this->bucketManager->deleteBucket('phpsdk-ci-test');
$this->assertNotNull($ret);
$this->assertNull($error);
}
public function testDomains()
{
list($ret, $error) = $this->bucketManager->domains($this->bucketName);
$this->assertNotNull($ret);
$this->assertNull($error);
}
public function testBucketInfo()
{
list($ret, $error) = $this->bucketManager->bucketInfo($this->bucketName);
$this->assertNotNull($ret);
$this->assertNull($error);
}
public function testBucketInfos()
{
list($ret, $error) = $this->bucketManager->bucketInfos('z0');
$this->assertNotNull($ret);
$this->assertNull($error);
}
public function testList()
{
list($ret, $error) = $this->bucketManager->listFiles($this->bucketName, null, null, 10);
$this->assertNotNull($ret['items'][0]);
$this->assertNotNull($ret['marker']);
$this->assertNull($error);
}
public function testListFilesv2()
{
list($ret, $error) = $this->bucketManager->listFilesv2($this->bucketName, null, null, 10);
$this->assertNotNull($ret);
$this->assertNull($error);
}
public function testBucketLifecycleRule()
{
list($ret, $error) = $this->bucketManager->bucketLifecycleRule($this->bucketName, 'demo', 'test', 80, 70);
$this->assertNotNull($ret);
$this->assertNull($error);
}
public function testGetbucketLifecycleRule()
{
list($ret, $error) = $this->bucketManager->getBucketLifecycleRules($this->bucketName);
$this->assertNotNull($ret);
$this->assertNull($error);
}
public function testUpdatebucketLifecycleRule()
{
list($ret, $error) = $this->bucketManager->updateBucketLifecycleRule(
$this->bucketName,
'demo',
'testupdate',
80,
70
);
$this->assertNotNull($ret);
$this->assertNull($error);
}
public function testDeleteBucketLifecycleRule()
{
list($ret, $error) = $this->bucketManager->deleteBucketLifecycleRule($this->bucketName, 'demo');
$this->assertNotNull($ret);
$this->assertNull($error);
}
public function testPutBucketEvent()
{
list($ret, $error) = $this->bucketManager->putBucketEvent(
$this->bucketName,
'bucketevent',
'test',
'img',
array('copy'),
$this->customCallbackURL
);
$this->assertNotNull($ret);
$this->assertNull($error);
}
public function testUpdateBucketEvent()
{
list($ret, $error) = $this->bucketManager->updateBucketEvent(
$this->bucketName,
'bucketevent',
'test',
'video',
array('copy'),
$this->customCallbackURL
);
$this->assertNotNull($ret);
$this->assertNull($error);
}
public function testGetBucketEvent()
{
list($ret, $error) = $this->bucketManager->getBucketEvents($this->bucketName);
$this->assertNotNull($ret);
$this->assertNull($error);
}
public function testDeleteBucketEvent()
{
list($ret, $error) = $this->bucketManager->deleteBucketEvent($this->bucketName, 'bucketevent');
$this->assertNotNull($ret);
$this->assertNull($error);
}
public function testStat()
{
list($stat, $error) = $this->bucketManager->stat($this->bucketName, $this->key);
$this->assertNotNull($stat);
$this->assertNull($error);
$this->assertNotNull($stat['hash']);
list($stat, $error) = $this->bucketManager->stat($this->bucketName, 'nofile');
$this->assertNull($stat);
$this->assertEquals(612, $error->code());
$this->assertNotNull($error->message());
list($stat, $error) = $this->bucketManager->stat('nobucket', 'nofile');
$this->assertNull($stat);
$this->assertEquals(631, $error->code());
$this->assertNotNull($error->message());
}
public function testDelete()
{
list($ret, $error) = $this->bucketManager->delete($this->bucketName, 'del');
$this->assertNull($ret);
$this->assertNotNull($error);
}
public function testRename()
{
$key = 'renamefrom' . rand();
$this->bucketManager->copy($this->bucketName, $this->key, $this->bucketName, $key);
$key2 = 'renameto' . $key;
list($ret, $error) = $this->bucketManager->rename($this->bucketName, $key, $key2);
$this->assertNull($error);
list($ret, $error) = $this->bucketManager->delete($this->bucketName, $key2);
$this->assertNull($error);
}
public function testCopy()
{
$key = 'copyto' . rand();
$this->bucketManager->delete($this->bucketName, $key);
list($ret, $error) = $this->bucketManager->copy(
$this->bucketName,
$this->key,
$this->bucketName,
$key
);
$this->assertNull($error);
//test force copy
list($ret, $error) = $this->bucketManager->copy(
$this->bucketName,
$this->key2,
$this->bucketName,
$key,
true
);
$this->assertNull($error);
list($key2Stat,) = $this->bucketManager->stat($this->bucketName, $this->key2);
list($key2CopiedStat,) = $this->bucketManager->stat($this->bucketName, $key);
$this->assertEquals($key2Stat['hash'], $key2CopiedStat['hash']);
list($ret, $error) = $this->bucketManager->delete($this->bucketName, $key);
$this->assertNull($error);
}
public function testChangeMime()
{
list($ret, $error) = $this->bucketManager->changeMime(
$this->bucketName,
'php-sdk.html',
'text/html'
);
$this->assertNull($error);
}
public function testPrefetch()
{
list($ret, $error) = $this->bucketManager->prefetch(
$this->bucketName,
'php-sdk.html'
);
$this->assertNull($error);
}
public function testFetch()
{
list($ret, $error) = $this->bucketManager->fetch(
'http://developer.qiniu.com/docs/v6/sdk/php-sdk.html',
$this->bucketName,
'fetch.html'
);
$this->assertArrayHasKey('hash', $ret);
$this->assertNull($error);
list($ret, $error) = $this->bucketManager->fetch(
'http://developer.qiniu.com/docs/v6/sdk/php-sdk.html',
$this->bucketName,
''
);
$this->assertArrayHasKey('key', $ret);
$this->assertNull($error);
list($ret, $error) = $this->bucketManager->fetch(
'http://developer.qiniu.com/docs/v6/sdk/php-sdk.html',
$this->bucketName
);
$this->assertArrayHasKey('key', $ret);
$this->assertNull($error);
}
public function testAsynchFetch()
{
list($ret, $error) = $this->bucketManager->asynchFetch(
'http://devtools.qiniu.com/qiniu.png',
$this->bucketName,
null,
'qiniu.png'
);
$this->assertArrayHasKey('id', $ret);
$this->assertNull($error);
list($ret, $error) = $this->bucketManager->asynchFetch(
'http://devtools.qiniu.com/qiniu.png',
$this->bucketName,
null,
''
);
$this->assertArrayHasKey('id', $ret);
$this->assertNull($error);
list($ret, $error) = $this->bucketManager->asynchFetch(
'http://devtools.qiniu.com/qiniu.png',
$this->bucketName
);
$this->assertArrayHasKey('id', $ret);
$this->assertNull($error);
}
public function testBatchCopy()
{
$key = 'copyto' . rand();
$ops = BucketManager::buildBatchCopy(
$this->bucketName,
array($this->key => $key),
$this->bucketName,
true
);
list($ret, $error) = $this->bucketManager->batch($ops);
$this->assertEquals(200, $ret[0]['code']);
$ops = BucketManager::buildBatchDelete($this->bucketName, array($key));
list($ret, $error) = $this->bucketManager->batch($ops);
$this->assertEquals(200, $ret[0]['code']);
}
public function testBatchMove()
{
$key = 'movefrom' . rand();
$this->bucketManager->copy($this->bucketName, $this->key, $this->bucketName, $key);
$key2 = $key . 'to';
$ops = BucketManager::buildBatchMove(
$this->bucketName,
array($key => $key2),
$this->bucketName,
true
);
list($ret, $error) = $this->bucketManager->batch($ops);
$this->assertEquals(200, $ret[0]['code']);
list($ret, $error) = $this->bucketManager->delete($this->bucketName, $key2);
$this->assertNull($error);
}
public function testBatchRename()
{
$key = 'rename' . rand();
$this->bucketManager->copy($this->bucketName, $this->key, $this->bucketName, $key);
$key2 = $key . 'to';
$ops = BucketManager::buildBatchRename($this->bucketName, array($key => $key2), true);
list($ret, $error) = $this->bucketManager->batch($ops);
$this->assertEquals(200, $ret[0]['code']);
list($ret, $error) = $this->bucketManager->delete($this->bucketName, $key2);
$this->assertNull($error);
}
public function testBatchStat()
{
$ops = BucketManager::buildBatchStat($this->bucketName, array('php-sdk.html'));
list($ret, $error) = $this->bucketManager->batch($ops);
$this->assertEquals(200, $ret[0]['code']);
}
public function testDeleteAfterDays()
{
$key = rand();
list($ret, $error) = $this->bucketManager->deleteAfterDays($this->bucketName, $key, 1);
$this->assertNotNull($error);
$this->bucketManager->copy($this->bucketName, $this->key, $this->bucketName, $key);
list($ret, $error) = $this->bucketManager->deleteAfterDays($this->bucketName, $key, 1);
$this->assertEquals(null, $ret);
}
public function testGetCorsRules()
{
list($ret, $err) = $this->bucketManager->getCorsRules($this->bucketName);
$this->assertNull($err);
}
public function testPutBucketAccessStyleMode()
{
list($ret, $err) = $this->bucketManager->putBucketAccessStyleMode($this->bucketName, 0);
$this->assertNull($err);
}
public function testPutBucketAccessMode()
{
list($ret, $err) = $this->bucketManager->putBucketAccessMode($this->bucketName, 0);
$this->assertNull($err);
}
public function testPutReferAntiLeech()
{
list($ret, $err) = $this->bucketManager->putReferAntiLeech($this->bucketName, 0, "1", "*");
$this->assertNull($err);
}
public function testPutBucketMaxAge()
{
list($ret, $err) = $this->bucketManager->putBucketMaxAge($this->bucketName, 31536000);
$this->assertNull($err);
}
public function testPutBucketQuota()
{
list($ret, $err) = $this->bucketManager->putBucketQuota($this->bucketName, -1, -1);
$this->assertNull($err);
}
public function testGetBucketQuota()
{
list($ret, $err) = $this->bucketManager->getBucketQuota($this->bucketName);
$this->assertNull($err);
}
public function testChangeType()
{
list($ret, $err) = $this->bucketManager->changeType($this->bucketName, $this->key, 0);
$this->assertNull($err);
list($ret, $err) = $this->bucketManager->changeType($this->bucketName, $this->key, 1);
$this->assertNull($err);
}
public function testChangeStatus()
{
list($ret, $err) = $this->bucketManager->changeStatus($this->bucketName, $this->key, 1);
$this->assertNull($err);
list($ret, $err) = $this->bucketManager->changeStatus($this->bucketName, $this->key, 0);
$this->assertNull($err);
}
}

View File

@@ -0,0 +1,145 @@
<?php
/**
* Created by IntelliJ IDEA.
* User: wf
* Date: 2017/6/21
* Time: AM8:46
*/
namespace Qiniu\Tests;
use Qiniu\Cdn\CdnManager;
use Qiniu\Http\Client;
class CdnManagerTest extends \PHPUnit_Framework_TestCase
{
protected $cdnManager;
protected $encryptKey;
protected $testStartDate;
protected $testEndDate;
protected $testGranularity;
protected $testLogDate;
protected $refreshUrl;
protected $refreshDirs;
protected $customDomain;
protected $customDomain2;
protected function setUp()
{
global $testAuth;
$this->cdnManager = new CdnManager($testAuth);
global $timestampAntiLeechEncryptKey;
$this->encryptKey = $timestampAntiLeechEncryptKey;
global $testStartDate;
$this->testStartDate = $testStartDate;
global $testEndDate;
$this->testEndDate = $testEndDate;
global $testGranularity;
$this->testGranularity = $testGranularity;
global $testLogDate;
$this->testLogDate = $testLogDate;
global $customDomain;
$this->refreshUrl = $customDomain . '/sdktest.png';
$this->refreshDirs = $customDomain;
$this->customDomain = $customDomain;
global $customDomain2;
$this->customDomain2 = $customDomain2;
}
public function testRefreshUrls()
{
list($ret, $err) = $this->cdnManager->refreshUrls(array($this->refreshUrl));
$this->assertNotNull($ret);
$this->assertNull($err);
}
public function testRefreshDirs()
{
list($ret, $err) = $this->cdnManager->refreshDirs(array($this->refreshDirs));
$this->assertNotNull($ret);
$this->assertNull($err);
}
public function testRefreshUrlsAndDirs()
{
list($ret, $err) = $this->cdnManager->refreshUrlsAndDirs(array($this->refreshUrl), array($this->refreshDirs));
$this->assertNotNull($ret);
$this->assertNull($err);
}
public function testGetCdnRefreshList()
{
list($ret, $err) = $this->cdnManager->getCdnRefreshList(null, null, null, 'success');
$this->assertNotNull($ret);
$this->assertNull($err);
}
public function testPrefetchUrls()
{
list($ret, $err) = $this->cdnManager->prefetchUrls(array($this->refreshUrl));
$this->assertNotNull($ret);
$this->assertNull($err);
}
public function testGetCdnPrefetchList()
{
list($ret, $err) = $this->cdnManager->getCdnPrefetchList(null, null, 'success');
$this->assertNotNull($ret);
$this->assertNull($err);
}
public function testGetBandwidthData()
{
list($ret, $err) = $this->cdnManager->getBandwidthData(
array($this->customDomain2),
$this->testStartDate,
$this->testEndDate,
$this->testGranularity
);
$this->assertNotNull($ret);
$this->assertNull($err);
}
public function testGetFluxData()
{
list($ret, $err) = $this->cdnManager->getFluxData(
array($this->customDomain2),
$this->testStartDate,
$this->testEndDate,
$this->testGranularity
);
$this->assertNotNull($ret);
$this->assertNull($err);
}
public function testGetCdnLogList()
{
list($ret, $err) = $this->cdnManager->getCdnLogList(array('fake.qiniu.com'), $this->testLogDate);
$this->assertNull($ret);
$this->assertNotNull($err);
}
public function testCreateTimestampAntiLeechUrl()
{
$signUrl = $this->cdnManager->createTimestampAntiLeechUrl($this->refreshUrl, $this->encryptKey, 3600);
$response = Client::get($signUrl);
$this->assertEquals($response->statusCode, 200);
$this->assertNull($response->error);
$signUrl = $this->cdnManager->createTimestampAntiLeechUrl(
$this->refreshUrl . '?qiniu',
$this->encryptKey,
3600
);
$response = Client::get($signUrl);
$this->assertEquals($response->statusCode, 200);
$this->assertNull($response->error);
}
}

View File

@@ -0,0 +1,21 @@
<?php
namespace Qiniu\Tests;
use Qiniu;
class Crc32Test extends \PHPUnit_Framework_TestCase
{
public function testData()
{
$a = '你好';
$b = \Qiniu\crc32_data($a);
$this->assertEquals('1352841281', $b);
}
public function testFile()
{
$b = \Qiniu\crc32_file(__file__);
$c = \Qiniu\crc32_file(__file__);
$this->assertEquals($c, $b);
}
}

View File

@@ -0,0 +1,25 @@
<?php
namespace Qiniu\Tests;
use Qiniu\Http\Client;
class DownloadTest extends \PHPUnit_Framework_TestCase
{
public function test()
{
global $testAuth;
$base_url = 'http://sdk.peterpy.cn/gogopher.jpg';
$private_url = $testAuth->privateDownloadUrl($base_url);
$response = Client::get($private_url);
$this->assertEquals(200, $response->statusCode);
}
public function testFop()
{
global $testAuth;
$base_url = 'http://sdk.peterpy.cn/gogopher.jpg?exif';
$private_url = $testAuth->privateDownloadUrl($base_url);
$response = Client::get($private_url);
$this->assertEquals(200, $response->statusCode);
}
}

View File

@@ -0,0 +1,52 @@
<?php
namespace Qiniu\Tests;
use Qiniu\Etag;
class EtagTest extends \PHPUnit_Framework_TestCase
{
public function test0M()
{
$file = qiniuTempFile(0);
list($r, $error) = Etag::sum($file);
unlink($file);
$this->assertEquals('Fto5o-5ea0sNMlW_75VgGJCv2AcJ', $r);
$this->assertNull($error);
}
public function testLess4M()
{
$file = qiniuTempFile(3 * 1024 * 1024);
list($r, $error) = Etag::sum($file);
unlink($file);
$this->assertEquals('Fs5BpnAjRykYTg6o5E09cjuXrDkG', $r);
$this->assertNull($error);
}
public function test4M()
{
$file = qiniuTempFile(4 * 1024 * 1024);
list($r, $error) = Etag::sum($file);
unlink($file);
$this->assertEquals('FiuKULnybewpEnrfTmxjsxc-3dWp', $r);
$this->assertNull($error);
}
public function testMore4M()
{
$file = qiniuTempFile(5 * 1024 * 1024);
list($r, $error) = Etag::sum($file);
unlink($file);
$this->assertEquals('lhvyfIWMYFTq4s4alzlhXoAkqfVL', $r);
$this->assertNull($error);
}
public function test8M()
{
$file = qiniuTempFile(8 * 1024 * 1024);
list($r, $error) = Etag::sum($file);
unlink($file);
$this->assertEquals('lmRm9ZfGZ86bnMys4wRTWtJj9ClG', $r);
$this->assertNull($error);
}
}

View File

@@ -0,0 +1,37 @@
<?php
namespace Qiniu\Tests;
use Qiniu\Processing\Operation;
use Qiniu\Processing\PersistentFop;
class FopTest extends \PHPUnit_Framework_TestCase
{
public function testExifPub()
{
$fop = new Operation('sdk.peterpy.cn');
list($exif, $error) = $fop->execute('gogopher.jpg', 'exif');
$this->assertNull($error);
$this->assertNotNull($exif);
}
public function testExifPrivate()
{
global $testAuth;
$fop = new Operation('private-res.qiniudn.com', $testAuth);
list($exif, $error) = $fop->execute('noexif.jpg', 'exif');
$this->assertNotNull($error);
$this->assertNull($exif);
}
public function testbuildUrl()
{
$fops = 'imageView2/2/h/200';
$fop = new Operation('testres.qiniudn.com');
$url = $fop->buildUrl('gogopher.jpg', $fops);
$this->assertEquals($url, 'http://testres.qiniudn.com/gogopher.jpg?imageView2/2/h/200');
$fops = array('imageView2/2/h/200', 'imageInfo');
$url = $fop->buildUrl('gogopher.jpg', $fops);
$this->assertEquals($url, 'http://testres.qiniudn.com/gogopher.jpg?imageView2/2/h/200|imageInfo');
}
}

View File

@@ -0,0 +1,59 @@
<?php
namespace Qiniu\Tests;
use Qiniu\Storage\FormUploader;
use Qiniu\Storage\UploadManager;
use Qiniu\Config;
class FormUpTest extends \PHPUnit_Framework_TestCase
{
protected $bucketName;
protected $auth;
protected $cfg;
protected function setUp()
{
global $bucketName;
$this->bucketName = $bucketName;
global $testAuth;
$this->auth = $testAuth;
$this->cfg = new Config();
}
public function testData()
{
$token = $this->auth->uploadToken($this->bucketName);
list($ret, $error) = FormUploader::put($token, 'formput', 'hello world', $this->cfg, null, 'text/plain', null);
$this->assertNull($error);
$this->assertNotNull($ret['hash']);
}
public function testData2()
{
$upManager = new UploadManager();
$token = $this->auth->uploadToken($this->bucketName);
list($ret, $error) = $upManager->put($token, 'formput', 'hello world', null, 'text/plain', null);
$this->assertNull($error);
$this->assertNotNull($ret['hash']);
}
public function testFile()
{
$key = 'formPutFile';
$token = $this->auth->uploadToken($this->bucketName, $key);
list($ret, $error) = FormUploader::putFile($token, $key, __file__, $this->cfg, null, 'text/plain', null);
$this->assertNull($error);
$this->assertNotNull($ret['hash']);
}
public function testFile2()
{
$key = 'formPutFile';
$token = $this->auth->uploadToken($this->bucketName, $key);
$upManager = new UploadManager();
list($ret, $error) = $upManager->putFile($token, $key, __file__, null, 'text/plain', null);
$this->assertNull($error);
$this->assertNotNull($ret['hash']);
}
}

View File

@@ -0,0 +1,79 @@
<?php
namespace Qiniu\Tests;
use Qiniu\Http\Client;
class HttpTest extends \PHPUnit_Framework_TestCase
{
public function testGet()
{
$response = Client::get('qiniu.com');
$this->assertEquals($response->statusCode, 200);
$this->assertNotNull($response->body);
$this->assertNull($response->error);
}
public function testGetQiniu()
{
$response = Client::get('upload.qiniu.com');
$this->assertEquals(405, $response->statusCode);
$this->assertNotNull($response->body);
$this->assertNotNull($response->xReqId());
$this->assertNotNull($response->xLog());
$this->assertNotNull($response->error);
}
public function testDelete()
{
$response = Client::delete('uc.qbox.me/bucketTagging', array());
$this->assertEquals($response->statusCode, 401);
$this->assertNotNull($response->body);
$this->assertNotNull($response->error);
}
public function testDeleteQiniu()
{
$response = Client::delete('uc.qbox.me/bucketTagging', array());
$this->assertEquals(401, $response->statusCode);
$this->assertNotNull($response->body);
$this->assertNotNull($response->xReqId());
$this->assertNotNull($response->xLog());
$this->assertNotNull($response->error);
}
public function testPost()
{
$response = Client::post('qiniu.com', null);
$this->assertEquals($response->statusCode, 200);
$this->assertNotNull($response->body);
$this->assertNull($response->error);
}
public function testPostQiniu()
{
$response = Client::post('upload.qiniu.com', null);
$this->assertEquals($response->statusCode, 400);
$this->assertNotNull($response->body);
$this->assertNotNull($response->xReqId());
$this->assertNotNull($response->xLog());
$this->assertNotNull($response->error);
}
public function testPut()
{
$response = Client::PUT('uc.qbox.me/bucketTagging', null);
$this->assertEquals($response->statusCode, 401);
$this->assertNotNull($response->body);
$this->assertNotNull($response->error);
}
public function testPutQiniu()
{
$response = Client::put('uc.qbox.me/bucketTagging', null);
$this->assertEquals(401, $response->statusCode);
$this->assertNotNull($response->body);
$this->assertNotNull($response->xReqId());
$this->assertNotNull($response->xLog());
$this->assertNotNull($response->error);
}
}

View File

@@ -0,0 +1,261 @@
<?php
namespace Qiniu\Tests;
/**
* imageprocess test
*
* @package Qiniu
* @subpackage test
* @author Sherlock Ren <sherlock_ren@icloud.com>
*/
class ImageUrlBuilderTest extends \PHPUnit_Framework_TestCase
{
/**
* 缩略图测试
*
* @test
* @return void
* @author Sherlock Ren <sherlock_ren@icloud.com>
*/
public function testThumbutl()
{
$imageUrlBuilder = new \Qiniu\Processing\ImageUrlBuilder();
$url = 'http://78re52.com1.z0.glb.clouddn.com/resource/gogopher.jpg';
$url2 = $url . '?watermark/1/gravity/SouthEast/dx/0/dy/0/image/'
. 'aHR0cDovL2Fkcy1jZG4uY2h1Y2h1amllLmNvbS9Ga1R6bnpIY2RLdmRBUFc5cHZZZ3pTc21UY0tB';
// 异常测试
$this->assertEquals($url, $imageUrlBuilder->thumbnail($url, 1, 0, 0));
$this->assertEquals($url, \Qiniu\thumbnail($url, 1, 0, 0));
// 简单缩略测试
$this->assertEquals(
$url . '?imageView2/1/w/200/h/200/ignore-error/1/',
$imageUrlBuilder->thumbnail($url, 1, 200, 200)
);
$this->assertEquals(
$url . '?imageView2/1/w/200/h/200/ignore-error/1/',
\Qiniu\thumbnail($url, 1, 200, 200)
);
// 输出格式测试
$this->assertEquals(
$url . '?imageView2/1/w/200/h/200/format/png/ignore-error/1/',
$imageUrlBuilder->thumbnail($url, 1, 200, 200, 'png')
);
$this->assertEquals(
$url . '?imageView2/1/w/200/h/200/format/png/ignore-error/1/',
\Qiniu\thumbnail($url, 1, 200, 200, 'png')
);
// 渐进显示测试
$this->assertEquals(
$url . '?imageView2/1/w/200/h/200/format/png/interlace/1/ignore-error/1/',
$imageUrlBuilder->thumbnail($url, 1, 200, 200, 'png', 1)
);
$this->assertEquals(
$url . '?imageView2/1/w/200/h/200/format/png/ignore-error/1/',
\Qiniu\thumbnail($url, 1, 200, 200, 'png', 2)
);
// 图片质量测试
$this->assertEquals(
$url . '?imageView2/1/w/200/h/200/format/png/interlace/1/q/80/ignore-error/1/',
$imageUrlBuilder->thumbnail($url, 1, 200, 200, 'png', 1, 80)
);
$this->assertEquals(
$url . '?imageView2/1/w/200/h/200/format/png/interlace/1/ignore-error/1/',
\Qiniu\thumbnail($url, 1, 200, 200, 'png', 1, 101)
);
// 多参数测试
$this->assertEquals(
$url2 . '|imageView2/1/w/200/h/200/ignore-error/1/',
$imageUrlBuilder->thumbnail($url2, 1, 200, 200)
);
$this->assertEquals(
$url2 . '|imageView2/1/w/200/h/200/ignore-error/1/',
\Qiniu\thumbnail($url2, 1, 200, 200)
);
}
/**
* 图片水印测试
*
* @test
* @param void
* @return void
* @author Sherlock Ren <sherlock_ren@icloud.com>
*/
public function waterImgTest()
{
$imageUrlBuilder = new \Qiniu\Processing\ImageUrlBuilder();
$url = 'http://78re52.com1.z0.glb.clouddn.com/resource/gogopher.jpg';
$url2 = $url . '?imageView2/1/w/200/h/200/format/png/ignore-error/1/';
$image = 'http://developer.qiniu.com/resource/logo-2.jpg';
// 水印简单测试
$this->assertEquals(
$url . '?watermark/1/image/aHR0cDovL2RldmVsb3Blci5xaW5pdS5jb20vcmVzb3VyY2UvbG9nby0yLmpwZw=='
. '/dissolve/100/gravity/SouthEast/',
$imageUrlBuilder->waterImg($url, $image)
);
$this->assertEquals(
$url . '?watermark/1/image/aHR0cDovL2RldmVsb3Blci5xaW5pdS5jb20vcmVzb3VyY2UvbG9nby0yLmpwZw=='
. '/gravity/SouthEast/',
$imageUrlBuilder->waterImg($url, $image, 101)
);
$this->assertEquals(
$url . '?watermark/1/image/aHR0cDovL2RldmVsb3Blci5xaW5pdS5jb20vcmVzb3VyY2UvbG9nby0yLmpwZw==/',
$imageUrlBuilder->waterImg($url, $image, 101, 'sdfsd')
);
$this->assertEquals(
$url . '?watermark/1/image/aHR0cDovL2RldmVsb3Blci5xaW5pdS5jb20vcmVzb3VyY2UvbG9nby0yLmpwZw=='
. '/dissolve/100/gravity/SouthEast/',
\Qiniu\waterImg($url, $image)
);
// 横轴边距测试
$this->assertEquals(
$url . '?watermark/1/image/aHR0cDovL2RldmVsb3Blci5xaW5pdS5jb20vcmVzb3VyY2UvbG9nby0yLmpwZw=='
. '/dissolve/100/gravity/SouthEast/dx/10/',
$imageUrlBuilder->waterImg($url, $image, 100, 'SouthEast', 10)
);
$this->assertEquals(
$url . '?watermark/1/image/aHR0cDovL2RldmVsb3Blci5xaW5pdS5jb20vcmVzb3VyY2UvbG9nby0yLmpwZw=='
. '/dissolve/100/gravity/SouthEast/',
\Qiniu\waterImg($url, $image, 100, 'SouthEast', 'sad')
);
// 纵轴边距测试
$this->assertEquals(
$url . '?watermark/1/image/aHR0cDovL2RldmVsb3Blci5xaW5pdS5jb20vcmVzb3VyY2UvbG9nby0yLmpwZw=='
. '/dissolve/100/gravity/SouthEast/dx/10/dy/10/',
$imageUrlBuilder->waterImg($url, $image, 100, 'SouthEast', 10, 10)
);
$this->assertEquals(
$url . '?watermark/1/image/aHR0cDovL2RldmVsb3Blci5xaW5pdS5jb20vcmVzb3VyY2UvbG9nby0yLmpwZw=='
. '/dissolve/100/gravity/SouthEast/',
\Qiniu\waterImg($url, $image, 100, 'SouthEast', 'sad', 'asdf')
);
// 自适应原图的短边比例测试
$this->assertEquals(
$url . '?watermark/1/image/aHR0cDovL2RldmVsb3Blci5xaW5pdS5jb20vcmVzb3VyY2UvbG9nby0yLmpwZw=='
. '/dissolve/100/gravity/SouthEast/dx/10/dy/10/ws/0.5/',
$imageUrlBuilder->waterImg($url, $image, 100, 'SouthEast', 10, 10, 0.5)
);
$this->assertEquals(
$url . '?watermark/1/image/aHR0cDovL2RldmVsb3Blci5xaW5pdS5jb20vcmVzb3VyY2UvbG9nby0yLmpwZw=='
. '/dissolve/100/gravity/SouthEast/',
\Qiniu\waterImg($url, $image, 100, 'SouthEast', 'sad', 'asdf', 2)
);
// 多参数测试
$this->assertEquals(
$url2 . '|watermark/1/image/aHR0cDovL2RldmVsb3Blci5xaW5pdS5jb20vcmVzb3VyY2UvbG9nby0yLmpwZw=='
. '/dissolve/100/gravity/SouthEast/',
$imageUrlBuilder->waterImg($url2, $image)
);
$this->assertEquals(
$url2 . '|watermark/1/image/aHR0cDovL2RldmVsb3Blci5xaW5pdS5jb20vcmVzb3VyY2UvbG9nby0yLmpwZw=='
. '/dissolve/100/gravity/SouthEast/',
\Qiniu\waterImg($url2, $image)
);
}
/**
* 文字水印测试
*
* @test
* @param void
* @return void
* @author Sherlock Ren <sherlock_ren@icloud.com>
*/
public function waterTextTest()
{
$imageUrlBuilder = new \Qiniu\Processing\ImageUrlBuilder();
$url = 'http://78re52.com1.z0.glb.clouddn.com/resource/gogopher.jpg';
$url2 = $url . '?imageView2/1/w/200/h/200/format/png/ignore-error/1/';
$text = '测试一下';
$font = '微软雅黑';
$fontColor = '#FF0000';
// 水印简单测试
$this->assertEquals($url . '?watermark/2/text/5rWL6K-V5LiA5LiL/font/5b6u6L2v6ZuF6buR/'
. 'fontsize/500/dissolve/100/gravity/SouthEast/', $imageUrlBuilder->waterText($url, $text, $font, 500));
$this->assertEquals(
$url . '?watermark/2/text/5rWL6K-V5LiA5LiL/font/5b6u6L2v6ZuF6buR/'
. 'dissolve/100/gravity/SouthEast/',
\Qiniu\waterText($url, $text, $font, 'sdf')
);
// 字体颜色测试
$this->assertEquals(
$url . '?watermark/2/text/5rWL6K-V5LiA5LiL/font/5b6u6L2v6ZuF6buR/fontsize/500/fill/'
. 'I0ZGMDAwMA==/dissolve/100/gravity/SouthEast/',
$imageUrlBuilder->waterText($url, $text, $font, 500, $fontColor)
);
$this->assertEquals(
$url . '?watermark/2/text/5rWL6K-V5LiA5LiL/font/5b6u6L2v6ZuF6buR/fill/I0ZGMDAwMA=='
. '/dissolve/100/gravity/SouthEast/',
\Qiniu\waterText($url, $text, $font, 'sdf', $fontColor)
);
// 透明度测试
$this->assertEquals(
$url . '?watermark/2/text/5rWL6K-V5LiA5LiL/font/5b6u6L2v6ZuF6buR/fontsize/500/fill/I0ZGMDAwMA=='
. '/dissolve/80/gravity/SouthEast/',
$imageUrlBuilder->waterText($url, $text, $font, 500, $fontColor, 80)
);
$this->assertEquals(
$url . '?watermark/2/text/5rWL6K-V5LiA5LiL/font/5b6u6L2v6ZuF6buR/fill/I0ZGMDAwMA=='
. '/gravity/SouthEast/',
\Qiniu\waterText($url, $text, $font, 'sdf', $fontColor, 101)
);
// 水印位置测试
$this->assertEquals(
$url . '?watermark/2/text/5rWL6K-V5LiA5LiL/font/5b6u6L2v6ZuF6buR/fontsize/500/fill/I0ZGMDAwMA=='
. '/dissolve/80/gravity/East/',
$imageUrlBuilder->waterText($url, $text, $font, 500, $fontColor, 80, 'East')
);
$this->assertEquals(
$url . '?watermark/2/text/5rWL6K-V5LiA5LiL/font/5b6u6L2v6ZuF6buR/fill/I0ZGMDAwMA==/',
\Qiniu\waterText($url, $text, $font, 'sdf', $fontColor, 101, 'sdfsdf')
);
// 横轴距离测试
$this->assertEquals(
$url . '?watermark/2/text/5rWL6K-V5LiA5LiL/font/5b6u6L2v6ZuF6buR/fontsize/500/fill/I0ZGMDAwMA=='
. '/dissolve/80/gravity/East/dx/10/',
$imageUrlBuilder->waterText($url, $text, $font, 500, $fontColor, 80, 'East', 10)
);
$this->assertEquals(
$url . '?watermark/2/text/5rWL6K-V5LiA5LiL/font/5b6u6L2v6ZuF6buR/fill/I0ZGMDAwMA==/',
\Qiniu\waterText($url, $text, $font, 'sdf', $fontColor, 101, 'sdfsdf', 'sdfs')
);
// 纵轴距离测试
$this->assertEquals(
$url . '?watermark/2/text/5rWL6K-V5LiA5LiL/font/5b6u6L2v6ZuF6buR/fontsize/500/fill/I0ZGMDAwMA=='
. '/dissolve/80/gravity/East/dx/10/dy/10/',
$imageUrlBuilder->waterText($url, $text, $font, 500, $fontColor, 80, 'East', 10, 10)
);
$this->assertEquals(
$url . '?watermark/2/text/5rWL6K-V5LiA5LiL/font/5b6u6L2v6ZuF6buR/fill/I0ZGMDAwMA==/',
\Qiniu\waterText($url, $text, $font, 'sdf', $fontColor, 101, 'sdfsdf', 'sdfs', 'ssdf')
);
// 多参数测试
$this->assertEquals(
$url2 . '|watermark/2/text/5rWL6K-V5LiA5LiL/font/5b6u6L2v6ZuF6buR/'
. 'fontsize/500/dissolve/100/gravity/SouthEast/',
$imageUrlBuilder->waterText($url2, $text, $font, 500)
);
$this->assertEquals(
$url2 . '|watermark/2/text/5rWL6K-V5LiA5LiL/font/5b6u6L2v6ZuF6buR/'
. 'fontsize/500/dissolve/100/gravity/SouthEast/',
\Qiniu\waterText($url2, $text, $font, 500)
);
}
}

View File

@@ -0,0 +1,66 @@
<?php
namespace Qiniu\Tests;
use Qiniu\Processing\Operation;
use Qiniu\Processing\PersistentFop;
class PfopTest extends \PHPUnit_Framework_TestCase
{
public function testPfop()
{
global $testAuth;
$bucket = 'testres';
$key = 'sintel_trailer.mp4';
$pfop = new PersistentFop($testAuth, null);
$fops = 'avthumb/m3u8/segtime/10/vcodec/libx264/s/320x240';
list($id, $error) = $pfop->execute($bucket, $key, $fops);
$this->assertNull($error);
list($status, $error) = $pfop->status($id);
$this->assertNotNull($status);
$this->assertNull($error);
}
public function testPfops()
{
global $testAuth;
$bucket = 'testres';
$key = 'sintel_trailer.mp4';
$fops = array(
'avthumb/m3u8/segtime/10/vcodec/libx264/s/320x240',
'vframe/jpg/offset/7/w/480/h/360',
);
$pfop = new PersistentFop($testAuth, null);
list($id, $error) = $pfop->execute($bucket, $key, $fops);
$this->assertNull($error);
list($status, $error) = $pfop->status($id);
$this->assertNotNull($status);
$this->assertNull($error);
}
public function testMkzip()
{
global $testAuth;
$bucket = 'phpsdk';
$key = 'php-logo.png';
$pfop = new PersistentFop($testAuth, null);
$url1 = 'http://phpsdk.qiniudn.com/php-logo.png';
$url2 = 'http://phpsdk.qiniudn.com/php-sdk.html';
$zipKey = 'test.zip';
$fops = 'mkzip/2/url/' . \Qiniu\base64_urlSafeEncode($url1);
$fops .= '/url/' . \Qiniu\base64_urlSafeEncode($url2);
$fops .= '|saveas/' . \Qiniu\base64_urlSafeEncode("$bucket:$zipKey");
list($id, $error) = $pfop->execute($bucket, $key, $fops);
$this->assertNull($error);
list($status, $error) = $pfop->status($id);
$this->assertNotNull($status);
$this->assertNull($error);
}
}

View File

@@ -0,0 +1,60 @@
<?php
namespace Qiniu\Tests;
use Qiniu\Storage\ResumeUploader;
use Qiniu\Storage\UploadManager;
use Qiniu\Config;
use Qiniu\Zone;
class ResumeUpTest extends \PHPUnit_Framework_TestCase
{
protected $bucketName;
protected $auth;
protected function setUp()
{
global $bucketName;
$this->bucketName = $bucketName;
global $testAuth;
$this->auth = $testAuth;
}
public function test4ML()
{
$key = 'resumePutFile4ML';
$upManager = new UploadManager();
$token = $this->auth->uploadToken($this->bucketName, $key);
$tempFile = qiniuTempFile(4 * 1024 * 1024 + 10);
list($ret, $error) = $upManager->putFile($token, $key, $tempFile);
$this->assertNull($error);
$this->assertNotNull($ret['hash']);
unlink($tempFile);
}
public function test4ML2()
{
$key = 'resumePutFile4ML';
$zone = new Zone(array('upload.fake.qiniu.com'), array('upload.qiniup.com'));
$cfg = new Config($zone);
$upManager = new UploadManager($cfg);
$token = $this->auth->uploadToken($this->bucketName, $key);
$tempFile = qiniuTempFile(4 * 1024 * 1024 + 10);
list($ret, $error) = $upManager->putFile($token, $key, $tempFile);
$this->assertNull($error);
$this->assertNotNull($ret['hash']);
unlink($tempFile);
}
// public function test8M()
// {
// $key = 'resumePutFile8M';
// $upManager = new UploadManager();
// $token = $this->auth->uploadToken($this->bucketName, $key);
// $tempFile = qiniuTempFile(8*1024*1024+10);
// list($ret, $error) = $upManager->putFile($token, $key, $tempFile);
// $this->assertNull($error);
// $this->assertNotNull($ret['hash']);
// unlink($tempFile);
// }
}

View File

@@ -0,0 +1,125 @@
<?php
namespace Qiniu\Tests;
use Qiniu;
use Qiniu\Zone;
class ZoneTest extends \PHPUnit_Framework_TestCase
{
protected $zone;
protected $zoneHttps;
protected $ak;
protected $bucketName;
protected $bucketNameBC;
protected $bucketNameNA;
protected $bucketNameFS;
protected $bucketNameAS;
protected function setUp()
{
global $bucketName;
$this->bucketName = $bucketName;
global $bucketNameBC;
$this->bucketNameBC = $bucketNameBC;
global $bucketNameNA;
$this->bucketNameNA = $bucketNameNA;
global $bucketNameFS;
$this->bucketNameFS = $bucketNameFS;
global $bucketNameAS;
$this->bucketNameAS = $bucketNameAS;
global $accessKey;
$this->ak = $accessKey;
$this->zone = new Zone();
$this->zoneHttps = new Zone('https');
}
public function testUpHosts()
{
list($ret, $err) = Zone::queryZone($this->ak, 'fakebucket');
$this->assertNull($ret);
$this->assertNotNull($err);
$zone = Zone::queryZone($this->ak, $this->bucketName);
$this->assertContains('upload.qiniup.com', $zone->cdnUpHosts);
$zone = Zone::queryZone($this->ak, $this->bucketNameBC);
$this->assertContains('upload-z1.qiniup.com', $zone->cdnUpHosts);
$zone = Zone::queryZone($this->ak, $this->bucketNameFS);
$this->assertContains('upload-z2.qiniup.com', $zone->cdnUpHosts);
$zone = Zone::queryZone($this->ak, $this->bucketNameNA);
$this->assertContains('upload-na0.qiniup.com', $zone->cdnUpHosts);
$zone = Zone::queryZone($this->ak, $this->bucketNameAS);
$this->assertContains('upload-as0.qiniup.com', $zone->cdnUpHosts);
}
public function testIoHosts()
{
$zone = Zone::queryZone($this->ak, $this->bucketName);
$this->assertEquals($zone->iovipHost, 'iovip.qbox.me');
$zone = Zone::queryZone($this->ak, $this->bucketNameBC);
$this->assertEquals($zone->iovipHost, 'iovip-z1.qbox.me');
$zone = Zone::queryZone($this->ak, $this->bucketNameFS);
$this->assertEquals($zone->iovipHost, 'iovip-z2.qbox.me');
$zone = Zone::queryZone($this->ak, $this->bucketNameNA);
$this->assertEquals($zone->iovipHost, 'iovip-na0.qbox.me');
$zone = Zone::queryZone($this->ak, $this->bucketNameAS);
$this->assertEquals($zone->iovipHost, 'iovip-as0.qbox.me');
}
public function testZonez0()
{
$zone = Zone::zonez0();
$this->assertContains('upload.qiniup.com', $zone->cdnUpHosts);
}
public function testZonez1()
{
$zone = Zone::zonez1();
$this->assertContains('upload-z1.qiniup.com', $zone->cdnUpHosts);
}
public function testZonez2()
{
$zone = Zone::zonez2();
$this->assertContains('upload-z2.qiniup.com', $zone->cdnUpHosts);
}
public function testZoneNa0()
{
$zone = Zone::zoneNa0();
$this->assertContains('upload-na0.qiniup.com', $zone->cdnUpHosts);
}
public function testZoneAs0()
{
$zone = Zone::zoneAs0();
$this->assertContains('upload-as0.qiniup.com', $zone->cdnUpHosts);
}
public function testQvmZonez0()
{
$zone = Zone::qvmZonez0();
$this->assertContains('free-qvm-z0-xs.qiniup.com', $zone->srcUpHosts);
}
public function testQvmZonez1()
{
$zone = Zone::qvmZonez1();
$this->assertContains('free-qvm-z1-zz.qiniup.com', $zone->srcUpHosts);
}
}

View File

@@ -0,0 +1,52 @@
<?php
// @codingStandardsIgnoreFile
require_once __DIR__ . '/../autoload.php';
use Qiniu\Auth;
$accessKey = getenv('QINIU_ACCESS_KEY');
$secretKey = getenv('QINIU_SECRET_KEY');
$testAuth = new Auth($accessKey, $secretKey);
$bucketName = 'phpsdk';
$key = 'php-logo.png';
$key2 = 'niu.jpg';
$testStartDate = '2020-08-18';
$testEndDate = '2020-08-19';
$testGranularity = 'day';
$testLogDate = '2020-08-18';
$bucketNameBC = 'phpsdk-bc';
$bucketNameNA = 'phpsdk-na';
$bucketNameFS = 'phpsdk-fs';
$bucketNameAS = 'phpsdk-as';
$dummyAccessKey = 'abcdefghklmnopq';
$dummySecretKey = '1234567890';
$dummyAuth = new Auth($dummyAccessKey, $dummySecretKey);
//cdn
$timestampAntiLeechEncryptKey = getenv('QINIU_TIMESTAMP_ENCRPTKEY');
$customDomain = "http://sdk.peterpy.cn";
$customDomain2 = "sdk.peterpy.cn";
$customCallbackURL = "https://qiniu.timhbw.com/notify/callback";
$tid = getenv('TRAVIS_JOB_NUMBER');
if (!empty($tid)) {
$pid = getmypid();
$tid = strstr($tid, '.');
$tid .= '.' . $pid;
}
function qiniuTempFile($size)
{
$fileName = tempnam(sys_get_temp_dir(), 'qiniu_');
$file = fopen($fileName, 'wb');
if ($size > 0) {
fseek($file, $size - 1);
fwrite($file, ' ');
}
fclose($file);
return $fileName;
}