本文整理汇总了PHP中Media::upload方法的典型用法代码示例。如果您正苦于以下问题:PHP Media::upload方法的具体用法?PHP Media::upload怎么用?PHP Media::upload使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Media
的用法示例。
在下文中一共展示了Media::upload方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: executeUploadBanners
public function executeUploadBanners()
{
$this->setLayout("backend");
$c = new Criteria();
$c->add(PrefPeer::LABEL, "newsletter");
$info = PrefPeer::doSelectOne($c);
if (!$info) {
$info = new Pref();
$info->setLabel("newsletter");
$info->save();
}
if ($this->getRequestParameter('submitted')) {
$request = $this->getRequest();
try {
$request->setParameter('parent', $info->getId());
if ($request->getFileName('banner1')) {
$request->setParameter('id', $this->getRequestParameter('banner1Id'));
$request->setParameter('attrLabel', 'newsletter468x60');
$media = Media::upload('banner1', "upload/newsletter", array("image/gif", "image/png", "image/jpeg", "image/pjpeg", "image/x-png"));
if ($media && $media->IsImage()) {
$media->resizeImage(null, 60, 468);
$media->resizeImage("thumbs", 30, 231);
}
}
if (!$media) {
$media = Document::getDocumentInstance($this->getRequestParameter('banner1Id'));
}
if ($media) {
$media->setDescription($this->getRequestParameter('banner1Url'));
$media->save();
}
if ($request->getFileName('banner2')) {
$request->setParameter('id', $this->getRequestParameter('banner2Id'));
$request->setParameter('attrLabel', 'newsletter160x600');
$media2 = Media::upload('banner2', "upload/newsletter", array("image/gif", "image/png", "image/jpeg", "image/pjpeg", "image/x-png"));
if ($media2 && $media2->IsImage()) {
$media2->resizeImage(null, 600, 160);
$media2->resizeImage("thumbs", 125, 40);
}
}
if (!$media2) {
$media2 = Document::getDocumentInstance($this->getRequestParameter('banner2Id'));
}
if ($media2) {
$media2->setDescription($this->getRequestParameter('banner2Url'));
$media2->save();
}
$infoVal = $this->getRequestParameter('info');
if (!$infoVal) {
$infoVal = null;
}
$info->setContent($infoVal);
$info->save();
} catch (Exception $e) {
$this->message = UtilsHelper::Localize("media.backend." . $e->getMessage());
}
}
$c = new Criteria();
$c->add(PrefPeer::LABEL, "newsletter");
$this->info = PrefPeer::doSelectOne($c);
$c = new Criteria();
$c->add(MediaPeer::LABEL, "newsletter468x60");
$this->banner1 = MediaPeer::doSelectOne($c);
$c = new Criteria();
$c->add(MediaPeer::LABEL, "newsletter160x600");
$this->banner2 = MediaPeer::doSelectOne($c);
}
示例2: display_msg
<?php
$page_title = 'All Image';
require_once 'includes/load.php';
// Checking userlevel
page_require_level(1);
$media_files = find_all('media');
if (isset($_POST['submit'])) {
$photo = new Media();
$photo->upload($_FILES['file_upload']);
if ($photo->process_media()) {
$session->msg('s', 'photo has been uploaded.');
redirect('media.php');
} else {
$session->msg('d', join($photo->errors));
redirect('media.php');
}
}
include_once 'layouts/header.php';
?>
<div class="row">
<div class="col-md-6">
<?php
echo display_msg($msg);
?>
</div>
<div class="col-md-12">
<div class="panel panel-default">
<div class="panel-heading clearfix">
<span class="glyphicon glyphicon-camera"></span>
示例3: validateAccountCreate
//.........这里部分代码省略.........
/* captcha */
if (empty($captcha_code)) {
$request->setError('errcaptcha_code', "Please fill the 'Verification code' field");
$result = false;
} else {
$code = $this->getUser()->getAttribute('captcha_code');
if (!$this->user && $code != $captcha_code) {
$request->setError('errcaptcha_code', "Wrong verification code");
$result = false;
}
}
/* end captcha */
/* terms */
if (empty($terms)) {
$request->setError('errterms', "You must accept the terms and conditions");
$result = false;
}
/* end terms */
}
/***** END COMMON *****/
/******* COMPANY ********/
if ($this->type == "company") {
/* label */
if (empty($label)) {
$request->setError('errlabel', "Please fill the 'Company name' field");
$result = false;
}
/* end label */
/* country */
if (empty($country)) {
$request->setError('errcountry', "Please fill the 'Country' field");
$result = false;
}
/* end country */
/* description */
if (empty($description)) {
$request->setError('errdescription', "Please fill the 'Description' field");
$result = false;
}
if ($request->getFileSize("logo") > 0) {
try {
$this->media = Media::upload('logo', "upload", array("image/gif", "image/png", "image/jpeg", "image/pjpeg", "image/x-png"));
if ($this->media && $this->media->IsImage()) {
$this->media->resizeImage(null, null, 800);
$this->media->resizeImage("thumbs", null, 100);
}
} catch (Exception $e) {
$request->setError('errlogo', UtilsHelper::Localize("media.backend." . $e->getMessage()));
$result = false;
}
}
/* end country */
/* city
if(empty($city))
{
$request->setError('errcity', "Please fill the 'city' field");
$result = false;
}
end city */
/* zip
if(empty($zip))
{
$request->setError('errzip', "Please fill the 'zip' field");
$result = false;
}
else
{
$myValidator = new sfNumberValidator();
$myValidator->initialize($this->getContext(), array(
'type' => "int"
));
if (!$myValidator->execute($zip, $error))
{
$request->setError('errzip', "The 'zip' field must be a number");
$result = false;
}
}
end zip */
/* address
if(empty($address))
{
$request->setError('erraddress', "Please fill the 'adress' field");
$result = false;
}
end address */
}
/***** END COMPANY *****/
/******** USER *********/
if ($this->type == "user" && $request->getFileSize("cv") > 0) {
try {
$this->media = Media::upload('cv', "upload", array("application/rtf", "application/msword", "text/plain", "text/richtext", "text/rtf", "application/pdf", "application/vnd.openxmlformats-officedocument.wordprocessingml.document", "application/vnd.oasis.opendocument.text", "text/html"));
} catch (Exception $e) {
$request->setError('errcv', UtilsHelper::Localize("media.backend." . $e->getMessage()));
$result = false;
}
}
/****** END USER *******/
}
return $result;
}
示例4: saveField
/**
* Save Field
*
* $contentID (int) = content ID
* $field (string) = field type
* $value = value of field to be saved
*
* @TODO:
* - Move this method to a Field class
* - Handle different types (arrays etc)
* - Normalise arrays / objects (convert to arrays for consistency in API)
*/
public function saveField($contentID, $field, $value)
{
# Handle Media Uploads
if ($this->isMedia($field)) {
$media = new Media($this->config);
## @TODO: Update this method to only
## accept the data it needs (field type)
$media->setMimeTypes($field);
if ($media->upload($value)) {
$value = $media->getPath();
}
}
# Data
$data = array('contentID' => $contentID, 'type' => $field, 'value' => $value);
# Add Field To Database
return $this->db->insert('fields', $data);
}
示例5: executeSaveMedia
public function executeSaveMedia()
{
try {
$media = Media::upload('attrFilename');
if ($media && $media->IsImage()) {
list($originalWidth, $originalHeight) = getimagesize($media->getServerAbsoluteUrl());
if ($originalWidth > $originalHeight && $originalWidth > 1500) {
$media->resizeImage(null, null, 1500);
} else {
if ($originalHeight > 1500) {
$media->resizeImage(null, 1500);
}
}
$media->resizeImage("thumbs", 100);
} else {
if ($media && in_array($media->getFiletype(), array("video/x-msvideo", "video/mpeg", "video/mp4", "video/quicktime", "video/x-ms-wmv", "video/avi", "video/wmv"))) {
$media->convertToFlv();
} else {
if ($media && in_array($media->getFiletype(), array("video/x-flv", "flv-application/octet-stream"))) {
$media->saveFlv();
} else {
if ($media && in_array($media->getFiletype(), array("application/octet-stream")) && substr($media->getFilename(), -4) == ".flv") {
$media->saveFlv();
} else {
if ($media && in_array($media->getFiletype(), array("application/binary")) && substr($media->getFilename(), -4) == ".mpg" || $media && in_array($media->getFiletype(), array("application/binary")) && substr($media->getFilename(), -5) == ".mpeg") {
$media->convertToFlv();
}
}
}
}
}
UtilsHelper::setBackendMsg("Saved");
} catch (Exception $e) {
UtilsHelper::setBackendMsg("Error while saving: " . UtilsHelper::Localize("media.backend." . $e->getMessage(), "en"), "error");
}
$this->forward(strtolower($this->getRequestParameter('moduleName')), "edit" . $this->getRequestParameter('documentName'));
}
示例6:
/**
* 网页授权
*/
//命名空间
use LaneWeChat\Core\WeChatOAuth;
/**
* Description: 获取CODE
* @param $scope snsapi_base不弹出授权页面,只能获得OpenId;snsapi_userinfo弹出授权页面,可以获得所有信息
* 将会跳转到redirect_uri/?code=CODE&state=STATE 通过GET方式获取code和state
*/
$redirect_uri = '获取CODE时,发送请求和参数给微信服务器,微信服务器会处理后将跳转到本参数指定的URL页面';
WeChatOAuth::getCode($redirect_uri, $state = 1, $scope = 'snsapi_base');
/**
* Description: 通过code换取网页授权access_token
* 首先请注意,这里通过code换取的网页授权access_token,与基础支持中的access_token不同。
* 公众号可通过下述接口来获取网页授权access_token。
* 如果网页授权的作用域为snsapi_base,则本步骤中获取到网页授权access_token的同时,也获取到了openid,snsapi_base式的网页授权流程即到此为止。
* @param $code getCode()获取的code参数
*/
$code = $_GET['code'];
WeChatOAuth::getAccessTokenAndOpenId($code);
/**
* Description: 获取用户信息 通过 - snsapi_base。即不弹出授权认证
* @param $code getCode()获得,采用跳转方式,需要自行$_GET先获得
*/
$code = $_GET['code'];
WeChatOAuth::getUserInfoBySnsapiBase($code, $redirect_uri = 'CODE不存在时需要传给getCode()的参数中的$redirect_uri');
//上传多媒体
Media::upload($filename, $type);
//下载多媒体
Media::download($mediaId);
示例7: time
if (!is_array($_FILES["myfile"]['name'])) {
$RandomNum = time();
$ImageName = str_replace(' ', '-', strtolower($_FILES['myfile']['name']));
$ImageType = $_FILES['myfile']['type'];
//"image/png", image/jpeg etc.
$ImageExt = substr($ImageName, strrpos($ImageName, '.'));
$ImageExt = str_replace('.', '', $ImageExt);
$ImageName = preg_replace("/\\.[^.\\s]{3,4}\$/", "", $ImageName);
$NewImageName = $ImageName . '-' . $RandomNum . '.' . $ImageExt;
move_uploaded_file($_FILES["myfile"]["tmp_name"], $output_dir . $NewImageName);
$media->name = $ImageName;
$media->type = $ImageType;
$media->extension = $ImageExt;
$media->newImageName = $NewImageName;
$media->propertyName = $property_name;
$media->upload();
$ret[$fileName] = $output_dir . $NewImageName;
} else {
$fileCount = count($_FILES["myfile"]['name']);
for ($i = 0; $i < $fileCount; $i++) {
$RandomNum = time();
$ImageName = str_replace(' ', '-', strtolower($_FILES['myfile']['name'][$i]));
$ImageType = $_FILES['myfile']['type'][$i];
//"image/png", image/jpeg etc.
$ImageExt = substr($ImageName, strrpos($ImageName, '.'));
$ImageExt = str_replace('.', '', $ImageExt);
$ImageName = preg_replace("/\\.[^.\\s]{3,4}\$/", "", $ImageName);
$NewImageName = $ImageName . '-' . $RandomNum . '.' . $ImageExt;
$ret[$NewImageName] = $output_dir . $NewImageName;
move_uploaded_file($_FILES["myfile"]["tmp_name"][$i], $output_dir . $NewImageName);
}
示例8: _import_wipo
function _import_wipo(&$args, &$start, &$count)
{
//ini_set("display_errors", 1);
//error_reporting(E_WARNING);
$result = '';
$start = $count = 0;
$ds = DIRECTORY_SEPARATOR;
$root = sfConfig::get('sf_root_dir') . $ds . sfConfig::get('sf_web_dir_name') . $ds . "uploads" . $ds;
$zipFile = $args[0];
$source = $root . "zip" . $ds . $zipFile;
$outDir = $root . "files" . $ds;
$zip = new ZipArchive();
$x = $zip->open($source);
// open the zip file to extract
//exit("\n ".$zipFile."\n");
//exit("\n x = ".$x."\n");
if ($x === true) {
$nameParts = explode(".", $zipFile);
$contestation = $nameParts[0];
//$contestationDate = date("Y-m-d", strtotime(substr($contestation, 0, 4)."-".substr($contestation, 4, 2)."-".substr($contestation, 6, 2)." +3months")) ;
//$contestationDateCompare = date("Y-m-d", strtotime(substr($contestation, 0, 4)."-".substr($contestation, 4, 2)."-".substr($contestation, 6, 2)." + 6 months")) ;
$contestationDateCompare = date("Y-m-d", strtotime(date("Y-m-d") . "+ 1 day"));
// + 1 day
//exit("\nContestationDate: ".$contestationDateCompare."\n");
$extract = $zip->extractTo($outDir);
// place in the directory with same name
$zip->close();
//unlink($source);
_echo_cms('SUCCESS: Your ZIP file has been unziped OK.');
_echo_cms('--------------------------------------------------------------------------------');
$files = array();
foreach (glob($outDir . '*.*') as $f) {
$files[] = $f;
if (substr($f, -4) == '.xml') {
$fileContent = file_get_contents($f);
if ($fileContent !== false && $fileContent > '') {
_echo_cms_title("Importing XML file: " . $f);
$cont = file_get_contents($f);
$enc = mb_detect_encoding($cont, 'ISO-8859-1');
//var_dump($enc);
$mainData = json_decode(json_encode((array) simplexml_load_string($cont, null, LIBXML_NOCDATA)), 1);
$trademarks = $mainData["TradeMarkTransactionBody"]["TransactionContentDetails"]["TransactionData"]["TradeMarkDetails"]["TradeMark"];
unset($mainData);
$ind = 1;
foreach ($trademarks as $t) {
//if($t['WordMarkSpecification']['MarkVerbalElementText'] != "makazi") continue;
$MarkRecords = $t['MarkRecordDetails']['MarkRecord'];
$doImport = false;
$doImport2 = false;
$date_mrs = array();
foreach ($MarkRecords as $mr) {
$contestationDate = $mr['RecordOppositionPeriod']['RecordOppositionPeriodEndDate'];
if ($contestationDate) {
if ($contestationDateCompare < $contestationDate) {
$date_mrs[] = $mr;
$doImport = true;
}
}
}
if (!$doImport) {
continue;
}
foreach ($date_mrs as $mr) {
if ($offCode = $mr["RecordOppositionPeriod"]["RecordInterestedOfficeCode"]) {
if ($offCode == "EM") {
$doImport2 = true;
break;
}
}
}
if (!$doImport2) {
continue;
}
$regNum = $t['BasicRegistrationApplicationDetails']['BasicRegistrationApplication']['BasicRegistrationDetails']['BasicRegistration']['BasicRegistrationNumber'];
if (!$regNum) {
continue;
}
$c = new Criteria();
$c->add(TrademarkPeer::REGISTER_NUMBER, $regNum);
$tmFound = TrademarkPeer::doSelectOne($c);
if ($tmFound) {
continue;
}
if (!$t['ApplicationNumber']) {
continue;
}
$c = new Criteria();
$c->add(TrademarkPeer::APPLICATION_NUMBER, $t['ApplicationNumber']);
$tmFound = TrademarkPeer::doSelectOne($c);
if ($tmFound) {
continue;
}
//upload image
if ($t['MarkImageDetails']) {
$imageName = str_replace('http://www.wipo.int/intreg/image/WO5', '', $t['MarkImageDetails']['MarkImage']['MarkImageFilename']);
$imageName = ltrim($imageName, '0');
$imageFormat = 'jpg';
if ($t['MarkImageDetails']['MarkImage']['MarkImageFileFormat'] == 'GIF') {
$imageFormat = 'gif';
}
//.........这里部分代码省略.........
示例9: executeAddNewTrademark
public function executeAddNewTrademark()
{
$this->setLayout(false);
$this->trademarkTypes = UtilsHelper::loadTrademarkTypes();
if ($trademark = Document::getDocumentInstance($this->getRequestParameter('trademark_id'))) {
if (get_class($trademark) != 'Trademark') {
$trademark = null;
}
}
if (!$trademark) {
$trademark = new Trademark();
}
$ownersArr = array();
$root = Rootfolder::getRootfolderByModule('clients');
$owners = Document::getChildrenOf($root->getId(), 'Client');
foreach ($owners as $ow) {
$ownersArr[$ow->getId()] = $ow->getLabel();
}
$this->ownersArr = $ownersArr;
$success = false;
if ($this->getRequestParameter('submit') > '') {
// check input data
$request = $this->getRequest();
$params = $request->getParameterHolder()->getAll();
//var_dump($params);
$errors = false;
$fields = array("label" => 'Наименование', "application_number" => 'Заявка номер', "kind" => 'Тип', "application_date" => 'Дата на заявяване', "expires_on" => 'Срок', "contestation" => 'Краен срок за опозиция', "nice_classes" => 'Класове по Ницска класификация', "rights_owner" => 'Притежател', "office_of_origin" => 'Държава на регистрация', "designated_contracting_party" => 'Държави в които е в сила');
foreach ($fields as $fl => $label) {
$val = trim($params[$fl]);
if ($val == '') {
if ($fl == 'rights_owner') {
if ($params['owner'] == '') {
$errors = true;
$request->setError('err' . $fl, '- ' . $label);
}
} else {
$errors = true;
$request->setError('err' . $fl, '- ' . $label);
}
}
}
$image = null;
if ($errors) {
UtilsHelper::setFlashMsg('Моля, въведете необходимите данни:<br>', UtilsHelper::MSG_ERROR);
} else {
if ($request->getFileName('image')) {
try {
$image = Media::upload('image', 'upload', array('image/gif', 'image/jpeg', 'image/jpg', 'image/png'));
//var_dump($image);
list($w, $h) = getimagesize($image->getServerAbsoluteUrl());
if ($w > $h) {
$image->resizeImage("thumbs", null, 105);
} else {
$image->resizeImage("thumbs", 95);
}
} catch (Exception $e) {
$errors = true;
$request->setError('errImage', '- ' . UtilsHelper::Localize('media.' . $e->getMessage()));
}
}
if ($errors) {
// remove uploaded image
if ($image) {
$image->delete();
}
UtilsHelper::setFlashMsg('Моля, коригирайте:<br>', UtilsHelper::MSG_ERROR);
}
}
// if everithing is OK
if (!$errors) {
//$trademark = new Brand();
$trademark->setLabel($params['label']);
$trademark->setFromSystem(1);
if ($params['owner'] > '') {
//$trademark->setClientId($params['owner']);
$client = Document::getDocumentInstance($params['owner']);
$trademark->setRightsOwner($client->getLabel());
} else {
$val = trim($params['rights_owner']);
$client = new Client();
$client->setLabel($val);
$client->save();
//$trademark->setClientId($client->getId());
$this->client = $client;
$trademark->setRightsOwner($val);
}
$trademark->setApplicationNumber($params['application_number']);
$trademark->setRegisterNumber($params['register_number']);
if ($params['registration_date']) {
$trademark->setRegistrationDate($params['registration_date']);
}
$trademark->setKind($params['kind']);
$trademark->setApplicationDate($params['application_date']);
$trademark->setStatus($params['status']);
$trademark->setExpiresOn($params['expires_on']);
$trademark->setContestation($params['contestation']);
$trademark->setPublications($params['publications']);
$trademark->setViennaClasses(str_replace(' ', '', $params['vienna_classes']));
$trademark->setColors($params['colors']);
$trademark->setNiceClasses(str_replace(' ', '', $params['nice_classes']));
//.........这里部分代码省略.........
示例10: executeSaveMedia
public function executeSaveMedia()
{
$hasError = false;
try {
$request = $this->getRequest();
$id = $this->getRequestParameter("id");
if ($this->getRequestParameter("submitEdit")) {
$fileName = $request->getFilePath('attrFilename');
if (!$id && !$fileName) {
UtilsHelper::setBackendMsg("Error: Please upload an image (JPG, GIF or JPG)!", "error");
return;
}
if ($fileName) {
$allowedArr = array("image/gif", "image/png", "image/jpg", "image/jpeg", "image/pjpeg");
$media = Media::upload('attrFilename', 'upload', $allowedArr);
$media->resizeImage("thumbs", null, 100);
}
}
} catch (Exception $e) {
$hasError = true;
UtilsHelper::setBackendMsg("Error while saving: " . $e->getMessage(), "error");
}
if (!$hasError) {
PanelService::redirect();
exit;
}
}