Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 12 years ago.
Improve this question
How do I install json in xampp server?
Json is a format; you don't install it, you implement it.
If you want to use the json format in your php website, there's an extension that provides functions you can use to encode data in a json format.
To install or use the extension, please see the installation page; depending on your version of php you may have the json extension already bundled with xampp. If you've got the latest version of xampp (windows install), it's ok to use the methods directly
Xampp is "shipped" with Apache, MySQL, PHP, Perl and support for JSON in PHP and Perl!
Json PHP
Json Perl: JSON::to_json(hash);
Simple PHP example from php.net
<?php
$arr = array ('a'=>1,'b'=>2,'c'=>3,'d'=>4,'e'=>5);
echo json_encode($arr);
?>
EDIT: Second example showing how to json_encode() a mysql query result:
<?php
$sth = mysql_query("SELECT ...");
$rows = array();
while($r = mysql_fetch_assoc($sth)) {
$rows[] = $r;
}
print json_encode($rows);
?>
EDIT 2: You are then able to convert JSON to XML using one of the described methods from this stackoverflow question.
Edit3: If you want to save the xml file to disc use
$myFile = "file.xml";
$fh = fopen($myFile, 'w') or die("can't open file");
$data = x; // replace x with the xml from your ajax result !!!!!
fwrite($fh, $data);
fclose($fh);
Related
This question already has answers here:
Intervention Image: Save image directly from an url with original file name and ext?
(3 answers)
Closed 2 years ago.
I have an API project using Laravel and these requires me to have a download and save it to public folder and in database.
Flow:
A field will come through the API call, i.e. through the company_logo field. It will come through as a URL: http://a.mktgcdn.com/p/Lr5Sfx0OllncmEPfQGX11ZqUZSmcUhbvc5a-u-FrMCU/1.0000/300x300.jpg. I need to grab the image and save it locally to a unique folder per listing and save it also to database.
I don't have code yet because I don't know what to do here in Laravel.
You can simply do that by using Intervention Image
You can find how to install here
$path = 'http://a.mktgcdn.com/p/Lr5Sfx0OllncmEPfQGX11ZqUZSmcUhbvc5a-u-FrMCU/1.0000/300x300.jpg';
$filename = basename($path);
Image::make($path)->save(public_path('yourimagefolder/' . $filename));
this will save the image. and following code will save it to database
$image = new ModelName();
$image->imagename =$filename;
$image->save();
Hope this help, you need to define $url and $filename variable
$data = file_get_contents( $url );
file_put_contents( public_path($filename), $data );
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I'm pretty basic at Perl, and I need to make a project for my university.
I want to download data from certain link, it is JSON data, so I know I have to use JSON::Parse module from CPAN.
But how to download content of link to my Perl variable? Should I use LWP get()?
Aren't you supposed to be learning Perl if it's a university project?
Anyway, your program will look something like this. It uses the LWP::Simple module to fetch the JSON data, and then JSON::Parse to process it into a Perl data structure
I've used printed the author value from each item of the array, as requested in your comment
use strict;
use warnings 'all';
use LWP::Simple 'get';
use JSON::Parse 'parse_json';
use constant URL => 'http://a.wykop.pl/observatory/entries/appkey,dJ4w7fXYpL';
my $json = get URL or die "Unable to get JSON data";
my $data = parse_json($json);
print "Authors:\n";
print " $_->{author}\n" for #$data;
output
Authors:
Snurq
AferaZaAfera
Devest
igorsped
Matt23
labla
poprawnie-niepoprawny
Parkero
Speed666
Xune
Gasior9
mikolajeq
Aztek2201
blogerbezbloga
Pan_wons
PanKaczucha
NieznanyAleAmbitny
dzika_kaczka_bez_dzioba
ilili
Bager
bmbcz01
hydrocyfolumpus
acarter
Doctor_Manhattan
strumienzgor
I am trying to figure out how to make a simple html code so that whenever anyone on the page types anything into the provided text box and hits submit, it adds that written text to an already existing .txt file on my server.
UPDATE 2/20/14 9:29AM: Well that's unfortunate. I kind of figured I required a .php but sadly my wepbage is hosted through homestead and they do not have .php functionality. Was just hoping there was a workaround. Thanks for the responses.
If your server can run php then the following page can be requested when the user clicks submit. (using post method)
<?php
$in = $_POST['name'];
$file = 'names.txt';
// Open the file to get existing content
$current = file_get_contents($file);
// Append a new person to the file
$current .= $in;
// Write the contents back to the file
file_put_contents($file, $current);
?>
You would have to use PHP to do this. Make the form action on your form link to a PHP script and inside have something like this.
<?php
$file = 'test.txt';
$currentText = file_get_contents($file);
$currentText .= $_POST['text'];
file_put_contents($file, $currentText);
?>
I have a ruby file namely sample.rb. I want to execute that from my form and, actually my ruby code when executed will write to a html file. So what i need to do is when i click on the button in the form it should execute the ruby code and then it has to open the html file that comes from execution in one of the frame in my form. Is it is possible? If possible! how to do?
What i have tried is
<?php
exec("./sample.rb")
?>
But what it does is. It simply took the url of the api that i have used in ruby code and it returns the json from that api.
May be you should use rails for that http://rubyonrails.org
You are invoking sample.rb as an external command, just like any other shell script. Therefore you have to capture and process its output yourself.
You say that "it returns the JSON from the api". That's fine, you can extract the data you are interested in, e.g.:
<?php
$json = exec("./sample.rb");
$data = json_decode($json);
$url = $data->url; # assuming there is an URL field
?>
Now you can for example output a link:
click
or generate some JavaScript:
<script>
window.location.href="<?php echo $url ?>";
</script>
or redirect the user via a HTTP header:
<?php
header("Location: $url");
?>
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 7 years ago.
Improve this question
Is there any JavaScript API available for tracking Fedex and UPS packages?
I googled for something like this but couldn't find anything. Then I decided to do it server side in ROR.
Here it is how to get UPS and Fedex xml request and response from their test servers.
For Fedex:
track_no = '111111111111' # This is a test tracking number
# This XML Request body for fedex
xml_req =
"<TrackRequest xmlns='http://fedex.com/ws/track/v3'><WebAuthenticationDetail><UserCredential><Key>YOUR_ACC_KEY</Key>
<Password>YOUR_ACC_PASSWORD</Password></UserCredential></WebAuthenticationDetail><ClientDetail>
<AccountNumber>YOUR_ACC_NUMBER</AccountNumber><MeterNumber>YOUR_ACC_METER_NUMBER</MeterNumber></ClientDetail>
<TransactionDetail><CustomerTransactionId>ActiveShipping</CustomerTransactionId></TransactionDetail>
<Version><ServiceId>trck</ServiceId><Major>3</Major><Intermediate>0</Intermediate><Minor>0</Minor></Version>
<PackageIdentifier><Value>#{track_no}</Value><Type>TRACKING_NUMBER_OR_DOORTAG</Type></PackageIdentifier>
<IncludeDetailedScans>1</IncludeDetailedScans></TrackRequest>"
path = "https://gatewaybeta.fedex.com:443/xml"
#this url connects to the test server of fedex
# for live server url is:"https://gateway.fedex.com:443/xml"
url = URI.parse(path)
http = Net::HTTP.new(url.host,url.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
response = http.post(url.path, xml_req)
response_body = response.body
res = response_body.gsub(/<(\/)?.*?\:(.*?)>/, '<\1\2>')
hash = Hash.from_xml(res.to_s)
And that's it! You will get response in hash variable, I converted xml response in to Hash because we can easily use Hash object at our view to display response data.
For UPS:
track_no = '1Z12345E1512345676' # This is a test tracking number
# This XML Request body for UPS
xml_req =
'<?xml version="1.0"?><AccessRequest xml:lang="en-US"><AccessLicenseNumber>YOUR_ACC_LICENCE_NUMBER</AccessLicenseNumber>
<UserId>YOUR_ACC_USER_ID</UserId><Password>YOUR_ACC_PASSWORD</Password></AccessRequest>
<?xml version="1.0"?><TrackRequest xml:lang="en-US"><Request><TransactionReference>
<CustomerContext>QAST Track</CustomerContext><XpciVersion>1.0</XpciVersion></TransactionReference>
<RequestAction>Track</RequestAction><RequestOption>activity</RequestOption></Request>
<TrackingNumber>#{track_no}</TrackingNumber></TrackRequest>'
path = "https://www.ups.com/ups.app/xml/Track"
url = URI.parse(path)
http = Net::HTTP.new(url.host,url.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
response = http.post(url.path, xml_req)
response_body = response.body
hash = Hash.from_xml(response_body.to_s)
This hash variable contains the response of UPS Tracking Request in Hash format.
another easy way to do it: Just create a hyperlink with the following href
UPS:
http://wwwapps.ups.com/WebTracking/track?loc=en_US&track.x=Track&trackNums=put_tracking_number_here
FEDEX:
http://fedex.com/Tracking?action=track&language=english&cntry_code=us&tracknumbers=put_tracking_number_here
(not as elegant, but quick, easy and gets the job done!)
Or you can use the active_shipping gem for a nicer and cleaner way to track your packages for Fedex and UPS