imageshack API cURL - post

I now the credentials are correct.
When I send a image through Form like this:(action="http://api.imageshack.com/v2/images/").
Its working fine but When I tried to send $ch = curl_init($url);
Its failed.
CODE:
enter code here
<form action="" method="post" enctype="multipart/form-data">
Select image to upload:
<input type="file" name="file" id="file" multiple>
<input type="text" name="auth_token" id="auth_token" value="xxxxxxxxxxxxxxxx">
<input type="text" name="api_key" id="api_key" value="xxxxxxxxxxxxxxx">
<input type="submit" value="Upload Image" >
</form>
$url = 'http://api.imageshack.com/v2/images/';
$temp = $_FILES["file"]['tmp_name'];
echo $temp."<br>" ;
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 240);
curl_setopt($ch, CURLOPT_POSTFIELDS, array(
'file'=> '#'.$temp,
"key" => "xxxxxxxxxxxxxxxxxxxx",
"auth_token" => "xxxxxxxxxxxxxxx"
));
curl_exec($ch);
I have also tried with Header: curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
And i get error from imageshack as json: {"error_code":1,"error_message":"Invalid image file. The file uploaded is not being detected as an image file.","error_info":{"Content-Type":null,"filesize":0}}

Related

How to import web site content dynamically into mautic

I am trying to use mautic for sending newsletter email to users, In order to send it to a segment of users I copied and pasted the html code of website in builder of channels -> email.
However how i can implement it dynamically, because I have some dynamic contents like:
<a href="https://www.website.com/?post_type=post&p=835383" target="_blank">
<img src="https://www.website.com/wp-content/uploads/2020/08/237228_cx__cy__cw__ch_-423x317.jpeg" width="100%" height="auto" style="display: block;" />
I do it through file_get_contents function like :
$html_string = file_get_contents('http://the url I want to import/');
$date = date('Y_m_d H:i');
$name=$_POST["newsletter"] . $date;
$subject=$_POST["subject"];
$segment=$_POST["segment"];
$result = httpPost("https://mautic url/api/emails/new",$html_string,$name,$subject,$segment);
function httpPost($url,$params,$name,$subject,$segment)
{
$header = array(
"Authorization: Basic encoded username and password"
);
$postData = array( 'name' => $name, 'subject' => $subject, 'customHtml' => $params ,'emailType'=>'list', 'lists'=> [$segment] );
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch,CURLOPT_HEADER, true);
curl_setopt($ch,CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_POST, count($postData));
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($postData));
$output=curl_exec($ch);
curl_close($ch);
return $output;
}

Targeted Time Zones List / Options

The existing code that I am working with provides a drop-down for the end
user to select a time zone.
My goal is to limit the choices down to
1. America
and
a. Option Eastern
value America/New_York
b. Option Central
value America/Chicago
c. Option Mountain DST
value America/Denver
d. Option Mountain no DST
value America/Phoenix
e. Option Pacific
value America/Los_Angeles
Narrowing it down to America was easy enough by simply commenting out the code.
Narrowing it down further to the 5 time zones is turning out to be beyond my pay grade.
Any advice?
$regions = [
# 'Africa' => DateTimeZone::AFRICA,
'America' => DateTimeZone::AMERICA,
# 'Antarctica' => DateTimeZone::ANTARCTICA,
# 'Aisa' => DateTimeZone::ASIA,
# 'Atlantic' => DateTimeZone::ATLANTIC,
# 'Europe' => DateTimeZone::EUROPE,
# 'Indian' => DateTimeZone::INDIAN,
# 'Pacific' => DateTimeZone::PACIFIC
];
$timezones = [];
foreach ($regions as $name => $mask) {
$zones = DateTimeZone::listIdentifiers($mask);
foreach ($zones as $timezone) {
$timezones[$name][$timezone] = $timezone;
}
}
$actualTimezone = JFactory::getSession()->get('user-timezone', $displayData['dateHelper']->getDate()->getTimezone()->getName(), 'Calendar');
?>
<form action="<?php echo JUri::base(); ?>" method="get" class="dp-timezone dp-form">
<span class="dp-timezone__label">
<?php echo $displayData['translator']->translate('COM_CALENDAR_CHOOSE_TIMEZONE'); ?>:
</span>
<select name="tz" class="dp-select dp-timezone__select">
<option value="UTC"<?php $actualTimezone == 'UTC' ? ' selected' : ''; ?>>
<?php echo $displayData['translator']->translate('JLIB_FORM_VALUE_TIMEZONE_UTC'); ?>
</option>
<?php foreach ($timezones as $region => $list) { ?>
<?php foreach ($list as $timezone => $name) { ?>
<option value="<?php echo $timezone; ?>"<?php echo $actualTimezone == $timezone ? ' selected' : ''; ?>>
<?php echo $displayData['translator']->translate($name); ?>
</option>
<?php } ?>
<?php } ?>
</select>
<input type="hidden" name="task" value="profile.tz" class="dp-input dp-input-hidden">
<input type="hidden" name="option" value="com_calendar" class="dp-input dp-input-hidden">
<input type="hidden" name="view" value="profile" class="dp-input dp-input-hidden">
<input type="hidden" name="return" value="<?php echo base64_encode(JUri::getInstance()->toString()); ?>" class="dp-input dp-input-hidden">
</form>

Send an Object data vit GET with AngularJS error

I'm having a problem with my GET request to API, here is:
self.search = {
init_date: new Date(),
end_date: new Date(),
statuses: {"Aberto": false, "Em andamento": false, "Fechado": false},
district: null,
address: null,
tags: null
};
$http.get(apiUrl + requestEndpoint + 'search', {params: self.search}).then(function(response){
self.gridOptions.data = response.data;
});
So, what is happening is that my params in API looks like this
{"end_date"=>"2016-07-07T22:58:11.943Z",
"init_date"=>"2016-07-07T22:58:11.943Z",
"statuses"=>"{\"Aberto\":false,\"Em andamento\":false,\"Fechado\":false}",
"format"=>:json,
"controller"=>"api/v1/requests",
"action"=>"search"}
and then I cannot read the statuses because it's a kind of string. How should I solve that?
Just to know... My Statuses value come from form in HTML with checkboxes
<div class="form-group">
<h5>Status</h5>
<div class="col-sm-12">
<input type="checkbox" name="status" id="aberto" class="k-checkbox" value="Aberto" ng-model="reportsCtrl.search.statuses['Aberto']">
<label class="k-checkbox-label" for="aberto"> Aberto </label>
<input type="checkbox" name="status" id="em-andamento" class="k-checkbox" value="Em andamento" ng-model="reportsCtrl.search.statuses['Em andamento']">
<label class="k-checkbox-label" for="em-andamento"> Em andamento </label>
<input type="checkbox" name="status" id="fechado" class="k-checkbox" value="Fechado" ng-model="reportsCtrl.search.statuses['Fechado']">
<label class="k-checkbox-label" for="fechado"> Fechado </label>
</div>
</div>
PS: My API is Rails
Regards.

Route [method] not defined

I am creating a form to insert data into database.version laravel5.1 but my code is not working.
resources\views\login.blade.php
<!-- Registration Form -->
<form action="{{ URL::route('postform_registration') }}" role="form" id="login_popup_form" method="post" name="login_popup_form">
<input type="hidden" name="_token" value="{{ csrf_token() }}">
<img id="close" src="{{ URL::asset('tradextek/img/close_irtiza.png') }}" alt="" onclick ="div_hide()">
<h2>Registration</h2>
<hr>
<div class="form-group">
<label for="">Your Email</label>
<input type="text" class="form-control" id="login_popup_email" name="login_popup_email" placeholder="Email" type="text">
</div>
<hr>
<div class="form-group">
<label for="">Your Password</label>
<input type="password" class="form-control"id="login_popup_password" name="login_popup_password" placeholder="Password...">
</div>
<hr>
<button type="submit" onclick="check_empty()" class="btn btn-primary">Submit</button>
</form>
<h3>
<?php
if(Session::has('key')){
echo Session::get('key');
}
?>
</h3>
routes.php
Route::post('/login',array(
'as' => 'postform',
'uses' => 'all_control#postform'
));
Route::post('/login',array(
'url' => 'postform_registration',
'uses' => 'all_control#postform_registration'
));
app/controllers/all_control
public function postform_registration(Request $request)
{
$email = $request->login_popup_email;
$password = $request->login_popup_password;
return redirect('login')->with('key', 'You have inserted successfully');
}
Error message
1)ErrorException in UrlGenerator.php line 296:
Route [postform] not defined. (View: C:\xampp\htdocs\project\resources\views\login.blade.php)
2)InvalidArgumentException in UrlGenerator.php line 296:
Route [postform] not defined.
By seeing this code, i guess that,there are two possibilities for your error.
in routes.php you have defined:
Route::post('/login',array(
'as' => 'postform',
'uses' => 'all_control#postform'
));
Route::post('/login',array(
'url' => 'postform_registration',
'uses' => 'all_control#postform_registration'
));
I can't understand why you have different routes entry for same url and same HTTP method in your case POST.
and you have defined POST method for routes
Route::post('/login',array(
'as' => 'postform',
'uses' => 'all_control#postform'
));
and other side you are passing GET Reqest from controller.
and second points:
Have you defined postform in all_control.php?

Get response as json after a post

I don't know if this is possible or not. I am working with asp.net mvc3 form. I am posting a form to a action and i want to get the response as json.
for example-
#using (Html.BeginForm("Action", "Controller", FormMethod.Post, new { Class = "formValidation", enctype = "multipart/form-data" }))
{
<dt>
<label>
Ad Image:
</label>
</dt>
<dd>
<input id="bannerImage" name="bannerImage" type="file" class="fileupload" />
</dd>
<dt>
<label>
JS Code:
</label>
</dt>
<dd>
#Html.TextAreaFor(m => m.JsCode, 10, 50, new { })
</dd>
<input type="submit" class="button red" value="Update Banner" />}
This is the form. And after submit I want to do something like
public ActionResult Action(Model editModel, HttpPostedFileBase file){
//do something
return Json(new{type="success"});
}
Then receive this from the form page and take some action. Is it possible?
if not please can you give me some hints to do this otherwise.
Use Ajax form instead of Html form. You can subscribe to OnSuccess javascript event and get output in format you like and also in json and process it there.

Resources