本文整理汇总了PHP中Package::from_upload方法的典型用法代码示例。如果您正苦于以下问题:PHP Package::from_upload方法的具体用法?PHP Package::from_upload怎么用?PHP Package::from_upload使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Package
的用法示例。
在下文中一共展示了Package::from_upload方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: upload
/**
* This handles uploads to a persions channel
* Need file posted as 'file' and the has poster as 'hash'
*/
public function upload()
{
switch ($this->format) {
case 'xml':
try {
$package = Package::from_upload(array('file' => $_FILES['file']['tmp_name'], 'sig' => $_POST['signatureBase64'], 'user' => $this->user), true);
if ($package->saved) {
echo 'Package uploaded succesfuly!';
}
} catch (Exception $e) {
$this->header("HTTP/1.0 500 Internal Server Error", 500);
echo $e->getMessage();
}
$this->has_rendered = true;
break;
default:
if ($_SESSION['upload_key'] !== $_POST['upload_key']) {
Nimble::flash('notice', 'Invalid Upload Key');
$this->redirect_to(url_for('LandingController', 'user_index', $this->user->username));
}
unset($_SESSION['upload_key']);
try {
$package = Package::from_upload(array('file' => $_FILES['file']['tmp_name'], 'user' => $this->user));
if ($package->saved) {
$this->redirect_to(url_for('LandingController', 'user_index', $this->user->username));
}
} catch (Exception $e) {
Nimble::flash('notice', $e->getMessage());
$this->redirect_to(url_for('ChannelController', 'upload'));
}
break;
}
}
示例2: create_package
public static function create_package()
{
$user = User::find_by_username('bob');
$file = FileUtils::join(NIMBLE_ROOT, 'test', 'data', 'bobs_other_package-0.0.1.tgz');
$package = Package::from_upload(array('file' => $file, 'user' => $user));
foreach (User::_find('all') as $user) {
$raiting = '0.' . $user->id;
PackageRating::_create(array('user_id' => $user->id, 'package_id' => $package->id, 'rating' => (double) $raiting));
}
}
示例3: testUploadFailbadSig
public function testUploadFailbadSig()
{
$localfile = FileUtils::join(NIMBLE_ROOT, 'test', 'data', 'joes_other_package-1.0.4.tgz');
$sig = PackageVerifyTest::calculatePackageSignature($localfile);
$user = User::find_by_username('joe');
try {
$p = Package::from_upload(array('file' => $localfile, 'sig' => $sig, 'user' => $user), true);
} catch (NimbleException $e) {
$this->assertEquals("Invalid package signature", $e->getMessage());
}
}
示例4: create_package
public static function create_package()
{
$user = User::find_by_username('bob');
$file = FileUtils::join(NIMBLE_ROOT, 'test', 'data', 'bobs_other_package-0.0.1.tgz');
$pp = Package::from_upload(array('file' => $file, 'user' => $user));
$p = Package::update($pp->id, array('url' => 'http://jetviper21.com'));
}