here is my function in a class called getminecraftprofile.php
basically it takes data from https://sessionserver.mojang.com/session/minecraft/profile/
dependant on the UUID of the user and gets an array that i can pick formation from.
the URL strings are base64 encoded so it decodes that as well.
public function getSkin()
{
$properties = $this->properties;
$encoded = json_encode($properties);
$imgUrl = json_decode(base64_decode(json_decode($encoded,true)[0]['value']),true) ['textures']['SKIN']['url'];
$img = file_get_contents($imgUrl);
echo($img);
}
this is the file that is passing in what user profile to find and get the skin of that profile. for most profiles it works perfectly and you can see it in action at http://jamesplanet.net/test/src/getskin.php?username=dinnerbone
<?php
include ($_SERVER["DOCUMENT_ROOT"] . '/test/src/getminecraftprofile.php' )?>
<?php
$profile = ProfileUtils::getProfile("useruser3");
//$result = $profile->getSkin();
$properties = $profile->getProperties();
$encoded = json_encode($properties);
$imgUrl = json_decode(base64_decode(json_decode($encoded,true)[0]['value']),true)['textures']['SKIN']['url'];
$img = file_get_contents($imgUrl);
var_dump($encoded);
echo('Texture URL Decoded: ' . $imgUrl );
it all grinds to a halt however if i say
$profile = ProfileUtils::getProfile("_jeb");
then it throws this at me
Warning: file_get_contents(): Filename cannot be empty in /Applications/AMPPS/www/test/src/getskin.php on line 10
string(908) "[{"name":"textures","value":"eyJ0aW1lc3RhbXAiOjE0MDM0ODE0Mjk2NDMsInByb2ZpbGVJZCI6IjdmM2ZjY2ZjYzUzOTQzNTdhZmEwMjExYTYyODc3MWU0IiwicHJvZmlsZU5hbWUiOiJfamViIiwiaXNQdWJsaWMiOnRydWUsInRleHR1cmVzIjp7fX0=","signature":"xIgM9w3MfZHMjlsZyrMDAF1CTAhhhhSWfjRqJgW3NNTCyotVkL9IMDN6ZzPIoNESFBlhwspxfKhrAC81+GlEUcFxLYilzO6qE+\/pYciNS78b9MxRK7R5xEoNNzFhXAyo9\/cW5X7V6bFxOB2MU9Fg7NXt\/B\/u4VypqGsbCA+OAm7Kgomlhkw3wkm1R1djfd5oBqwlCKhTWxt4k4mQJzThsqE5ffLdTcPeMoipezw4NHAV1QJfXZZlGsEDG\/KkzUDh6eOz+QufYvhcxGrOAfwJ4TzlLbu0QyT8IRIu0E5LY96sTSecWQ27W7TzsumXiXrkpOSLZrOi5yqGFMmfOEHqo8dLRnxhoNmyQpzN2rE4OvNBwKqvzOeRbigOzQSSg5xupydFFLdc20Pj9CXcTB18K12fXt6W8FJ+AzYUccPrSx\/1RJALkef9W5DCxNLOLLR5yIS8Irff3\/Gn2sRwTG8EXJz+6qRB50e02jdyTv9DZz853w+TAVoNtSkBB8W9aC08XUSCFFg1KAaLILkRi8H+76BE1pZKraPAoW8MpsUbd6J+6k0kU5lqdtiJZ1PtDssVMA+p9MwtOmQqD7n4hPXehULBv4+phQjZi37s1I6ZWYrQBE7raq3ZKfDx9ztccmHEyk\/VHSboo0QmtM8iCOCOC1l0Jv9QrV\/YQRZil03x+OQ="}]" Texture URL Decoded:
i know there is data there because its visible before the base64 decode.
where is it going wrong?
here is an example of what is being parsed
{"id":"069a79f444e94726a5befca90e38aaf5","name":"Notch","properties":[{"name":"textures","value":"eyJ0aW1lc3RhbXAiOjE0MDM0ODE0MjIwNDUsInByb2ZpbGVJZCI6IjA2OWE3OWY0NDRlOTQ3MjZhNWJlZmNhOTBlMzhhYWY1IiwicHJvZmlsZU5hbWUiOiJOb3RjaCIsImlzUHVibGljIjp0cnVlLCJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvYTExNmU2OWE4NDVlMjI3ZjdjYTFmZGRlOGMzNTdjOGM4MjFlYmQ0YmE2MTkzODJlYTRhMWY4N2Q0YWU5NCJ9LCJDQVBFIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvM2Y2ODhlMGU2OTliM2Q5ZmU0NDhiNWJiNTBhM2EyODhmOWM1ODk3NjJiM2RhZTgzMDg4NDIxMjJkY2I4MSJ9fX0=","signature":"TJieaNbZrHGmA7V3n8jn0V/ZVPXAy4EK44lxsh3kidK4JML8BEEZZjt/1eixbbXHGMH39e122UO7ehX2PIutuIIK7ZhvAo6wy8yMG34rPxjuyg0jzZe/tZjKv/kq7Bi78m6PErfwBsaUxjkCD3J0sqLXyvOy9rQ2CbYGKTxnVtOZGzxIaQqC5QH/2We704cMUJ3wIgN9FckppVA2E+DYu0G8iFlvYQnjxxIclokv3jOcPrYwVq0COWJaDrGd0+o+dKUfTfiT/k1OLBuceGDmqjb9CmcbEeTFFRJrmA6XEoA6OHZbLOMpIPLtEs8LbZqBH38Cuf+izPGLl1e28bITwPUdpABzvxaxKoYB3XYnWvtAqyfvzsCEgoBVnV7psx1W+kWU9xjCxC591457bollR2KVrSQBv7p0KBm4qVaVPKa01bjcMfcDDx5PRBIcL6XECVmKoeqh+qUrrf1Z9WN0l4OEujmRd8/tbJMjtJTdqCUZ5ak7urJHl8iTNNLqjx/Dsi47DeZvfUGdSC6ivpDIDBQv3myBLNnHqE7/+Z8DGKa+Bf/nQW0sMdVsNFOxIeiXMyXpWAHMw3/Ee21aMWEUq+rD8l4CD2FTZkQ/gv18y3y7CR9fYIKU+EPccnDUtyF+Y257UtCUag7i0vlkiBpIh46jhpjIkhR+iAG4URqQA6I="}]}
Related
I admit I have a lot of trouble with this problem (I don't know much about PHP and SOAP.
I have to get product pictures for an ecommerce via a web service of a provider (SOAP).
As shown in the picture below, the product pictures are converted to base64.
Example for a product picture
I need to retrieve all the pictures to upload them in a folder on my site and write the path of each picture in a CSV file.
The code below allows me to retrieve all the products that are sent to me via the web service. I recover all the products with the function RecupEtatStock() then, with the help of a loop, for each product I search if there are images with the function RecupPhotoProduct().
$wsdl = "https://sinex-saas.com/B00UWSUG9Z34TN22/Services/WebServiceStandard.asmx?WSDL";
$client = new SoapClient($wsdl);
$password = "????";
$username = "????";
$reffab = 4;
$codefab = 2;
$i = 0;
$fp = fopen(plugin_dir_path(__FILE__).'file.csv', 'w+');
$dataRecupererEtatStock = RecupEtatStock($username, $password, $client);
foreach ($dataRecupererEtatStock as $fields) {
$dataRecupPhotoProduit = RecupPhotoProduit($username, $password, $client, $fields->CodeFab, $fields->RefFab, $i);
$fields->image = $dataRecupPhotoProduit;
fputcsv($fp, get_object_vars($fields));
$i+=1;
}
fclose($fp);
Here is what the RecupPhotoProduct() function looks like. If there is no picture, the function returns null, otherwise it retrieves what the save_image() function returns.
function RecupPhotoProduit($pUsername, $pPassword, $pClient, $pCodeFab, $pReffab, $pi) {
$optionsRecupererPhotoProduit = array(
'user' => $pUsername,
'password' => $pPassword,
'codeFab' => $pCodeFab,
'refFab' => $pReffab,
);
$responseRecupererPhotoProduit = $pClient->RecupererPhotoProduit($optionsRecupererPhotoProduit);
$array = get_object_vars($responseRecupererPhotoProduit);
if(empty($array)) {
$responseRecupererPhotoProduit = null;
} else {
$responseRecupererPhotoProduit = $responseRecupererPhotoProduit->RecupererPhotoProduitResult;
$responseRecupererPhotoProduit = save_image($responseRecupererPhotoProduit, $pi);
}
return $responseRecupererPhotoProduit;
}
The above function allows me to retrieve the string in "RetrievePhotoProductResult" from this XML result:
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<RecupererPhotoProduitResponse xmlns="http://tempuri.org/">
<RecupererPhotoProduitResult>/9j/4AAQSkZJRgABAQEAYABgAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0aHBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL/2wBDAQkJCQwLDBgNDRgyIRwhMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjL/wAARCACEAJoDASIAAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFB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KKKACiiigDlfFaq1xDkZ+Tkeo5rmJFCeYcZKhj83fBA5+oPNFFd9H4EWtiYIDLs5/1rJnPPyrkH6jpn061EVUoG2jmNWx2+Y4I+nf60UVoMQgLkjqN5z7r3/EdasxKvzAqCAyJg9we34dqKKTA19EQRa9tGTmQjLcnhW5+tdjRRXHX+IiW4UUUViIKKKKACiiigD//2Q==</RecupererPhotoProduitResult>
</RecupererPhotoProduitResponse>
</soap:Body>
</soap:Envelope>
So for this example, the MIME64 encoded text is :
/9j/4AAQSkZJRgABAQEAYABgAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0aHBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL/2wBDAQkJCQwLDBgNDRgyIRwhMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjL/wAARCACEAJoDASIAAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uHi4+Tl5ufo6erx8vP09fb3+Pn6/8QAHwEAAwEBAQEBAQEBAQAAAAAAAAECAwQFBgcICQoL/8QAtREAAgECBAQDBAcFBAQAAQJ3AAECAxEEBSExBhJBUQdhcRMiMoEIFEKRobHBCSMzUvAVYnLRChYkNOEl8RcYGRomJygpKjU2Nzg5OkNERUZHSElKU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6goOEhYaHiImKkpOUlZaXmJmaoqOkpaanqKmqsrO0tba3uLm6wsPExcbHyMnK0tPU1dbX2Nna4uPk5eb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FQIKKKKACiiigAooooAK5zV4At+2AMyKHA/Q/wAh+ddHWD4p0a/1fT0GmXiWt5ESUd03KwI6H05wcj0rWjPklcadmcNrcW/WlhcAxS221lJID5J4PseRSW09zZtYrb3Tw2VoCDbquRJGeMMTz8p6fWqkFn4iiviPEgWS7UGNHjUKrp25HXJ6H1FXNvOeOecsevbJ+vQ+hrsVpK5ZcXX9Vjt74taQT3Cu32OJX2h1HRZGPRsZORxVj+3yLm2iFkTbyRlpp9w/cnjaNvVsnPI6YrPCLjjpj3zgf+zL+opGjOfuKfYPxz2+jdvep9nEa02LT+JNVFjdG1tIILxZGW28xt8bIMfO+OQeuVHSm3Opajdais4vZFhERiNuwyjM3RyeufTHrVQqM5JA77iSfof6Gp4og3AQH+HZnGfVf6imoRWwilY20dtfWdvbjyovNLiMMcEk5bP+1nmuvt7YSSLCQP3xEYHTIP3sf8B3H8K5W6h1F1d9JTzL5cNCHUHc2cZx6joR7V0/g/QdftH+3eIr6Ke4KnbFHGAFJxzn2GR/wI8VNSooxaE3Y7GiiiuEgKKKKACiiigAooooAKKKKACiiigDlfFaq1xDkZ+Tkeo5rmJFCeYcZKhj83fBA5+oPNFFd9H4EWtiYIDLs5/1rJnPPyrkH6jpn061EVUoG2jmNWx2+Y4I+nf60UVoMQgLkjqN5z7r3/EdasxKvzAqCAyJg9we34dqKKTA19EQRa9tGTmQjLcnhW5+tdjRRXHX+IiW4UUUViIKKKKACiiigD//2Q==
And this is what my save_image() function looks like. It decodes the base64 image from the "RetrievePhotoProductResult" part of the previous XML and uploads it to my WordPress plugin directory.
function save_image( $base64_img, $title ) {
$base64_img = str_replace('data:image/png;base64,', '', $base64_img);
$base64_img = str_replace(' ', '+', $base64_img);
$data = base64_decode($base64_img);
$file = plugin_dir_path(__FILE__) . $title . '.png';
return file_put_contents($file, $data);
}
But here is my problem, the images download well in my directory. However, I can't open them.
For example, if I try to open them with Paint, this is what I get (Whether I open an image with Paint or not, it's the same thing. I think the problem is the base64 encoding):
Paint cannot read this file. It is not a valid bitmap file or its format is not currently supported.
And if I want to access an image from my ecommerce site, I have a simple white dot that appears:
I have a simple white dot that appears
And here is what the base64 string looks like after decoding:
the base64 string
Do you know how I could download a base64 image via a php web service?
<?php
$encode = "/9j/4AAQSkZJRgABAQEAYABgAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0aHBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL/2wBDAQkJCQwLDBgNDRgyIRwhMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjL/wAARCACEAJoDASIAAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uHi4+Tl5ufo6erx8vP09fb3+Pn6/8QAHwEAAwEBAQEBAQEBAQAAAAAAAAECAwQFBgcICQoL/8QAtREAAgECBAQDBAcFBAQAAQJ3AAECAxEEBSExBhJBUQdhcRMiMoEIFEKRobHBCSMzUvAVYnLRChYkNOEl8RcYGRomJygpKjU2Nzg5OkNERUZHSElKU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6goOEhYaHiImKkpOUlZaXmJmaoqOkpaanqKmqsrO0tba3uLm6wsPExcbHyMnK0tPU1dbX2Nna4uPk5ebn6Onq8vP09fb3+Pn6/9oADAMBAAIRAxEAPwD3+iiigAooooAKKK5jxlZvq1pHpq3VxbROGaZoJNhYYwASOSOScewqoRcnZDSuUfEmq2k2pRw21zFLJCpD7HB2HnIJHTjr3rB3Fmz9/P4E5/lk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qkFn4iiviPEgWS7UGNHjUKrp25HXJ6H1FXNvOeOecsevbJ+vQ+hrsVpK5ZcXX9Vjt74taQT3Cu32OJX2h1HRZGPRsZORxVj+3yLm2iFkTbyRlpp9w/cnjaNvVsnPI6YrPCLjjpj3zgf+zL+opGjOfuKfYPxz2+jdvep9nEa02LT+JNVFjdG1tIILxZGW28xt8bIMfO+OQeuVHSm3Opajdais4vZFhERiNuwyjM3RyeufTHrVQqM5JA77iSfof6Gp4og3AQH+HZnGfVf6imoRWwilY20dtfWdvbjyovNLiMMcEk5bP+1nmuvt7YSSLCQP3xEYHTIP3sf8B3H8K5W6h1F1d9JTzL5cNCHUHc2cZx6joR7V0/g/QdftH+3eIr6Ke4KnbFHGAFJxzn2GR/wI8VNSooxaE3Y7GiiiuEgKKKKACiiigAooooAKKKKACiiigDlfFaq1xDkZ+Tkeo5rmJFCeYcZKhj83fBA5+oPNFFd9H4EWtiYIDLs5/1rJnPPyrkH6jpn061EVUoG2jmNWx2+Y4I+nf60UVoMQgLkjqN5z7r3/EdasxKvzAqCAyJg9we34dqKKTA19EQRa9tGTmQjLcnhW5+tdjRRXHX+IiW4UUUViIKKKKACiiigD//2Q==";
$decode = base64_decode($encode);
$size = getImageSizeFromString($decode);
var_dump($size);
if (empty($size['mime']) || strpos($size['mime'], 'image/') !== 0) {
die('Base64 value is not a valid image');
}
$ext = substr($size['mime'], 6);
$img_file = "filename.{$ext}";
file_put_contents($img_file, $decode);
echo $ext;
?>
this will work for all valid images.
I've come to some problems. I've made a wordpress plugin, which automatically gets the most 20 recent Instagram posts and then, in theory, it should make me let to insert the newest image as a shortcode in to the post. Basically, I get an error message displaying:
Notice: Uninitialized string offset: 0 in D:\XEMP\htdocs\xd\wordpress\wp-content\plugins\insta-live\insta-live.php on line 29
Now, the code to reproduce this is:
//define Access token
$accesst= "PUT YOUR INSTAGRAM ACCESS TOKEN HERE";
//userid
$userid= YOUR INSTAGRAM USER ID HERE;
//image count to get
$count=20;
//get api contents
$content = file_get_contents('https://api.instagram.com/v1/users/self/media/recent/?access_token='.$accesst.'&count='.$count);
//converting JSON to object
$standardres = json_decode($content, true);
//array method
foreach($standardres['data'] as $photo) {
$imageData = base64_encode(file_get_contents($photo['images']['standard_resolution']['url']));
$images[] = '<img src="data:image/jpeg;base64,' . $imageData . '" />';
}
//create functions for shortcodes
function fone($images){
return $images[0]; //naudok tik [one]
}
//shortcodes
add_shortcode( 'one', 'fone');
?>
Any ideas how to solve this? A var_dump() gives me the images above the header..
The API documentation shows this example:
$fileId = '1ZdR3L3qP4Bkq8noWLJHSr_iBau0DNT4Kli4SxNc2YEo';
$content = $driveService->files->export($fileId,
'application/pdf',
array('alt' => 'media')
);
How do I show the image in my HTML?
(I've already figured out how authorization with the Google API works.)
You can embed the raw image data using base64_encode
Your API call is returning a GuzzleHttp Response object, so you can get the raw data by calling:
$rawData = $response->getBody()->getContents();
// Alternatively, you should be able to cast it to a string (I would try the first method then this alternative if you want)
$rawData = (string) $response->getBody();
To embed that raw data as an html <img /> you can do something like:
// Convert to base64 encoding
$imageData = base64_encode($rawData);
// Get the content-type of the image from the response
$contentType = $response->getHeader("content-type");
// Format the image src: data:{mime};base64,{data}
$src = 'data: '.$contentType.';base64,'.$imageData;
// Echo out a sample image
echo '<img src="'.$src.'" />';
Source
I found that App Store API support additional information about application.
$keyword = $this->input->post('keyword');
$appstore_api = 'http://itunes.apple.com/search?country=US&entity=software&term='.$keyword;
$data = file_get_contents($appstore_api);
echo $data;
here is the PHP code that I wrote.
I get this result.
{ "resultCount":50, "results": [ {"kind":"software", "features":[], "supportedDevices":["all"], "isGameCenterEnabled":false, "artistViewUrl":"http://itunes.apple.com/us/artist/burbn-inc./id389801255?uo=4", "artworkUrl60":"http://a2.mzstatic.com/us/r1000/105/Purple/v4/f3/0e/e2/f30ee271-c564-ec21-02d6-d020bd2ff38b/Icon.png", "screenshotUrls":["http://a3.mzstatic.com/us/r1000/102/Purple/v4/2d/25/d3/2d25d348-74e9-8365-208c-45e64af73ed6/mzl.xnvocmpt.png", "http://a1.mzstatic.com/us/r1000/077/Purple/v4/04/18/b3/0418b375-c0c1-18c1-1aef-07555c99af46/mzl.pkthtqtv.png", "http://a2.mzstatic.com/us/r1000/069/Purple/v4/31/08/65/31086528-2f37-bca0-71f3-c3095e698f35/mza_8774562250786021670.png", "http://a3.mzstatic.com/us/r1000/091/Purple/v4/95/a2/65/95a265bb-b9f0-8732-9fe4-823ffbc9aba0/mza_5807950548098772841.png"], "ipadScreenshotUrls":[], "artworkUrl512":"http://a4.mzstatic.com/us/r1000/089/Purple/v4/44/76/7f/44767fb5-4cb2-25bf-5361-25138b8c2aeb/mzl.ntalagmr.png",
The question is that how can I extract the variable named "artworkUrl512" ?
I tried like this but failed.
$image_url = $data->results->artworkUrl512;
$image_url2 = $data['results']['artworkUrl512'];
Can you help me how to extract icon image url?
$data is json encoded. Use json_decode():
http://php.net/manual/en/function.json-decode.php
$data = json_decode($json, true);
echo $data['results'][0]['artworkUrl512'];
I want to pass an image as a byte array from php to a .NET web serice.
The php client is as follows:
<?php
class Image{
public $ImgIn = array();
}
$file = file_get_contents('chathura.jpg');
$ImgIn = str_split($file);
foreach ($ImgIn as $key=>$val) { $ImgIn[$key] = ord($val); }
$client = new SoapClient('http://localhost:64226/Service1.asmx?wsdl');
$result = $client->PutImage(new Image());
echo $result->PutImageResult;
//print_r($ImgIn);
?>
Here is the web method in ASP.NET web service:
[WebMethod]
public string PutImage(byte[] ImgIn)
{
System.IO.MemoryStream ms =
new System.IO.MemoryStream(ImgIn);
System.Drawing.Bitmap b =
(System.Drawing.Bitmap)Image.FromStream(ms);
b.Save("imageTest", System.Drawing.Imaging.ImageFormat.Jpeg);
return "test";
}
When I run this the image content is correctly read to ImgIm array in php client. (In this instance the image had 16992 elements.) However when the array is passed to the web service method it contains only 5 elements (the first 5 elements of the image)
Can I know what is the reason for the loss of data ? How can I avoid it ?
Thanks
file_get_contents returns the file contents as string which is not useful for binary files such as images. Try this:
$handle = fopen("chathura.jpg", "r");
$contents = fread($handle, filesize("chathura.jpg"));
fclose($handle);
$client = new SoapClient('http://localhost:64226/Service1.asmx?wsdl');
$result = $client->PutImage($contents);
Guys, it seems that it is not going to be any use to try and pass data as a byte array as PHP anyway converts it to a string when sending. This conversion seems to introduce control characters to the string, making it only send a part of the byte array. I got this to work by sending a base64 encoded string and decoding inside the server.
My client side code:
<?php
class Image{
public $ImgIn = '';
}
//ini_set("memory_limit","20M");
$imageData = file_get_contents('chathura.jpg');
$encodedData = base64_encode($imageData);
$Img = new Image();
$Img->ImgIn = $encodedData;
$client = new SoapClient('http://localhost:64226/Service1.asmx?wsdl');
$result = $client->PutImage($Img);
echo($result->PutImageResult);
?>
ASP .NET web service code:
[WebMethod]
public string PutImage(String ImgIn)
{
byte[] ImgInBytes = Convert.FromBase64String(ImgIn);
System.IO.MemoryStream ms =
new System.IO.MemoryStream(ImgInBytes);
System.Drawing.Bitmap b =
(System.Drawing.Bitmap)Image.FromStream(ms);
b.Save("C:\\imageTest.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
return "success";
}