本文整理匯總了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'));
}