i can't save uploaded image of my plugin in osclass - osclass

$avatar = Params::getParam('pAvatar');
if(Params::getParam('pAvatar') <> '') {
$user = User::newInstance()->findByPrimaryKey($userId);
if($user['s_profile_img'] <> '') {
#unlink(osc_content_path() . 'uploads/user-images/' . $user['s_profile_img']);
}
osc_base64_to_image(Params::getParam('pAvatar'));
}

Related

Image upload type for Graphql magento2

Is there any way to upload image using graphql without using base64 format in magento2
public function uploadFile($fileData)
{
// convert base64 string to image and save as file on server.
$uploadedFileName = "";
$fileName = '';
if (isset($fileData['name'])) {
$fileName = $fileData['name'];
} else {
$fileName = rand() . time();
}
if (isset($fileData['filecontent'])) {
$mediaPath = $this->fileSystem->getDirectoryRead(DirectoryList::MEDIA)->getAbsolutePath();
$originalPath = 'ModuleName/Attachments/';
$mediaFullPath = $mediaPath . $originalPath;
if (!file_exists($mediaFullPath)) {
mkdir($mediaFullPath, 0775, true);
}
/* Check File is exist or not */
$fullFilepath = $mediaFullPath . $fileName;
if ($this->fileDriver->isExists($fullFilepath)) {
$fileName = rand() . time() . $fileName;
}
$fileContent = base64_decode($fileData['filecontent']);
$savedFile = fopen($mediaFullPath . $fileName, "wb");
fwrite($savedFile, $fileContent);
fclose($savedFile);
$uploadedFileName = "/" . $fileName ;
}
return $uploadedFileName;
}
See more: https://magento.stackexchange.com/a/351629/101754

resize of image not working in codeigniter 3

I've been attempting to resize a image in codeigniter 3 ,but no luck! I have the resize inside the ddoo_upload() function , the resize() will work , when it comes to one image field within that form and if you will add two image field within that form , then the resize() will not work. Not sure what is wrong!
This is what i have tried for image upload,The code below shows my upload function (and resize within it)
if (isset($_FILES['destiimg']) && $_FILES['destiimg']['name'] != '') {
$filename = $this->ddoo_upload('destiimg', '2000' , '336');
} else {
$filename = NULL;
}
if (isset($_FILES['destiimg_thumb']) && $_FILES['destiimg_thumb']['name'] != '') {
$destbannerthumb_imgnew = $this->ddoo_upload('destiimg_thumb', 300 , 225);
} else {
$destbannerthumb_imgnew = NULL;
}
function ddoo_upload($filename, $width, $height)
{
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'jpg|jpeg|png|gif';
$config['overwrite'] = FALSE;
$config['encrypt_name'] = TRUE;
$this->load->library('upload', $config);
if ( ! $this->upload->do_upload($filename)) {
echo $this->upload->display_errors();die();
return NULL;
} else {
$data = $this->upload->data();
$filename = $data['file_name'];
$config1['image_library'] = 'gd2';
$config1['source_image'] = $this->upload->upload_path.$this->upload->file_name;
//$config1['create_thumb'] = TRUE;
$config1['maintain_ratio'] = FALSE;
$config1['width'] = $width;
$config1['height'] = $height;
$this->load->library('image_lib', $config1);
$this->image_lib->resize();
return $filename;
}
}
The upload works fine , but the resize has some issue.
You are missing some config options when loading image_lib.
Look at the manual, you didn't specified source_image (and other options).
If you want to use something advanced, there is good library called Image Moo. It's older but good working with CI3.

How to validate files with Yii2 getInstancesByName uploaded from API?

I'm working on a mobile app, the Yii2 is used as backend API, the problem that I can not validate the uploaded files, any idea how I can do it?
public static function uploadPicture ($vid) {
$model = new Pictures ();
$model->load(\Yii::$app->getRequest()->getBodyParams(), '');
$model->vid_image = \yii\web\UploadedFile::getInstancesByName('vid_image');
$imageDir = Yii::$app->params[ 'uploadDir' ];
//if ( $model->validate() AND !empty($model->vid_image) ) { //does not work
if ( !empty($model->vid_image) ) {
foreach ( $model->vid_image as $images => $image) {
$model->name = "t_" . time() . "_i_" . uniqid() . '.' . $image->extension;
$model->vid = $vid;
echo $image->hasError;//return empty
//Yii::$app->end();
//if ( $model->save() and $model->validate() ) { // does not work
if(1==1 and $model->validate()){ // $model->validate() always empty!!!
$image->saveAs($imageDir . '/' . $model->name);
Yii::$app->getResponse()->setStatusCode(201);
$id = implode(',', array_values($model->getPrimaryKey(true)));
Yii::info("[pic.21] image: " . $model->name . " uploaded to: " . $imageDir, __METHOD__);
} elseif ( $model->hasErrors() ) {
$response = \Yii::$app->getResponse();
$response->setStatusCode(500);
throw new ServerErrorHttpException('Failed to create the object for unknown reason. [APIx001]');
}
}
}
return $model;
}
The files are uploaded without validation.
Thanks,

change where clause of query based on different input laravel 5.6

how to change the where condition of query based on different input in laravel
controller.
for example if i have law_id as input then the where condition
should use this law_id and fetch data.
this is my code:
$law_id = Input::get('law_id');
$subject_matter = Input::get('subject_matter');
$case_no = Input::get('case_no');
$court = Input::get('court');
$legal_data = DB::table('tbl_legal_form')->select('*');
if($law_id != '')
{
$legal_data = $legal_data->where('legal_applicable_law',$law_id);
}
if($subject_matter != '')
{
$legal_data = $legal_data->where('subject_matter',$subject_matter);
}
$result = $legal_data->get();
What is the best way to do this..?
$legal_data = DB::table('tbl_legal_form');
if($law_id != '')
{
$legal_data = $legal_data->where('legal_applicable_law',$law_id)->get();
}
if($subject_matter != '')
{
$legal_data = $legal_data->where('subject_matter',$subject_matter)->get();
}
$result = $legal_data;

How to grab contacts from gmail using google API's and contact grabber in PHP?

In my project i want to grab the contacts from gmail using google API's. I provide three keys such as client id, client secret and signature key. When i trying to get contacts the pop-up window is showing error message "Signature key must be formatted". What i have done wrong? Thanks in advance.
Here is my code
keyConfig.php
<?php
$apiRequestUrl = "https://stescodes.com/api/contactsapi.aspx"; // StesCodes contact grabber API request url
$originalsignaturekey = "lxFWDA5ng36sdvlFGukof75vyi";//replace with your signature key
$gmailConsumerKey = "1009516162377-n5s7lo5b4dvlt8e7s3rt12f8i02lpk1f.apps.googleusercontent.com";
$gmailConsumerSecret = "raCUba1smsZCzrVNjqFIqiqC";
$YahooConsumerKey = "your yahoo api key";
$YahooConsumerSecret = "your yahoo api key";
$LiveConsumerKey = "your live api key";
$LiveConsumerSecret = "your live api key";
$fbConsumerKey = "your facebook api key";
$fbConsumerSecret = "your facebook api key";
$callbackurl = "http://localhost/grab/oauth.php";// eg: return url after user authentication http://yourdomain/oauth.php
$currentdirpath = "http://dev.stescodes.com/";//your current web directory path eg:http://yourdomain/
?>
oauth.php
<?php
session_start();
?>
<?php include 'keyConfig.php'; ?>
<html>
<head><title></title>
<script>
function redirectrequest(a)
{
window.location = a;
}
function closepopup(a,b,c,d) {
window.opener.startGrabbingContactsOauth(a,b,c,d);
window.self.close();
}
</script>
</head>
<body>
<?php
$servicename = "gmail";
$token = "";
$ConsumerKey = "";
$ConsumerSecret="";
$tokensecret="";
$tokenverifier="";
$flag=0;
$parameters="";
if($_GET['currpage']!=null)
$_SESSION['currpage']=$_GET['currpage'];
if($_SESSION['currpage']=="gmail")
{
$servicename = "gmail";
$ConsumerKey = $gmailConsumerKey;
$ConsumerSecret = $gmailConsumerSecret;
if ($_GET['code'] != null)
{
$token = $_GET['code'];
$tokensecret = $_SESSION['tokensecret'];
$flag = 1;
}
}
else if($_SESSION['currpage']=="yahoo")
{
$servicename = "yahoo";
$ConsumerKey = $YahooConsumerKey;
$ConsumerSecret = $YahooConsumerSecret;
if (($_GET['oauth_token'] != null) && ($_GET['oauth_verifier'] != null))
{
$token = $_GET['oauth_token'];
$tokenverifier = $_GET['oauth_verifier'];
$tokensecret = $_SESSION['tokensecret'];
$flag = 1;
}
}
else if($_SESSION['currpage']=="facebook")
{
$servicename = "facebook";
$ConsumerKey = $fbConsumerKey;
$ConsumerSecret = $fbConsumerSecret;
if (($_GET['code'] != null))
{
$token = $_GET['code'];
$tokenverifier = "";
$tokensecret = "";
$flag = 1;
}
}
else if(($_SESSION['currpage']=="msn") || ($_SESSION['currpage']=="hotmail") || ($_SESSION['currpage']=="msnmessenger"))
{
$servicename = $_SESSION['currpage'];
$ConsumerKey = $LiveConsumerKey;
$ConsumerSecret = $LiveConsumerSecret;
//Live settings
if ($_GET["code"] != null)
{
$token = $_GET["code"];
$flag = 1;
}
}
if ($flag == 1)
{
$parameters = "type=accesstoken&ServiceName=" . urlencode($servicename) . "&ConsumerKey=" . urlencode($ConsumerKey) . "&ConsumerSecret=" . urlencode($ConsumerSecret);
$parameters = $parameters . "&ReturnUrl=" . urlencode($callbackurl) . "&Token=" . urlencode($token) . "&TokenSecret=" . urlencode($tokensecret) . "&TokenVerifier=" . urlencode($tokenverifier);
$result = file_get_contents($apiRequestUrl."?".$parameters);
$authdetails = json_decode($result,true);
$_SESSION['token'] = $authdetails[details][token];
$_SESSION['tokensecret'] = $authdetails[details][tokenSecret];
$_SESSION['uid'] = $authdetails[details][userID];
$_SESSION['tokenverifier'] = $_SESSION['tokenverifier'];
$_SESSION["consumerkey"] = $ConsumerKey;
$_SESSION["consumersecret"] = $ConsumerSecret;
echo "<SCRIPT LANGUAGE=\"javascript\"> closepopup('".$servicename."',". $result .",'".$ConsumerKey."','".$ConsumerSecret."');</SCRIPT>";
}
else
{
$parameters = "type=authenticationurl&ServiceName=" . urlencode($servicename) . "&ConsumerKey=" . urlencode($ConsumerKey) . "&ConsumerSecret=" . urlencode($ConsumerSecret);
$parameters = $parameters . "&ReturnUrl=" . urlencode($callbackurl) ;
$result = file_get_contents($apiRequestUrl."?".$parameters);
$authdetails = json_decode($result,true);
$_SESSION['token'] = $authdetails[details][token];
$_SESSION['tokensecret'] = $authdetails[details][tokenSecret];
$_SESSION['uid'] = $authdetails[details][userID];
$_SESSION['tokenverifier'] = $tokenverifier;
echo "<SCRIPT LANGUAGE=\"javascript\"> redirectrequest('".$authdetails[details][authUrl]."'); </SCRIPT>";
}
?>