1,105,391 Community Members

[ask] byte array

Member Avatar
ressaince
Newbie Poster
3 posts since May 2010
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

i have an ASP web services to change byte array that given from the client and change it to a file and save it in the web server
the code is like this :

[WebMethod]
        public string UploadFile(byte[] f, string fileName)
        {
           
            try
            {
               
                MemoryStream ms = new MemoryStream(f);

               
               
            String path="/myfile/";
            String location=HttpContext.Current.Server.MapPath(path);
             FileStream fs = new FileStream(HttpContext.Current.Server.MapPath(path)+fileName, FileMode.Create);
           
         
               
                ms.WriteTo(fs);

               
                ms.Close();
                fs.Close();
               

               
                return "OK";
            }
            catch (Exception ex)
            {
             
                return ex.Message.ToString();
            }
        }

the web services need byte array and file name..
i build the client in php
upload.php

<html>
<body>
<form action="action1.php" method="post" enctype="multipart/form-data">
 Pilih File Anda:
<input type="file" name="myfile" />
<input type="submit" value="Upload" />
</form>
</body>
<html>

and action1.php the code is:

<?php
require_once('nusoap.php');
$client = new nusoap_client('http://192.168.254.160/testuploadah/FileUploader.asmx?WSDL', 'wsdl','','', '', '');
$err = $client->getError();
if ($err) {
echo '<h2>Constructor error</h2><pre>' . $err . '</pre>';
}
if(is_uploaded_file($_FILES['myfile']['tmp_name'])){
    $uploadFile = $_FILES['myfile'];
////how can read byte array of $uploadFile so i can send to web services???
////are php can only send string to web services????
$params=array();
$params->f=???????????????
$params->fileName=$_FILES['myfile']['name'];

$result = $client->call('UploadFile', $params,'', '', false, true);
if ($client->fault) {
echo '<h2>Fault</h2><pre>';
print_r($result);
echo '</pre>';
} else {
 //Check for errors
$err = $client->getError();
if ($err) {
//// Display the error
echo '<h2>Error</h2><pre>' . $err . '</pre>';
} else {
//// Display the result
echo '<h2>Result</h2><pre>';
print_r($result);
echo '</pre>';
}
}
}
?>

how can i Send the byte array parameter to the web services,so the web services can started????

i still can resolve this problem,the web services always return an error because i can't send byte array

Member Avatar
sourcebits
Junior Poster
102 posts since Dec 2008
Reputation Points: 6 [?]
Q&As Helped to Solve: 14 [?]
Skill Endorsements: 0 [?]
 
0
 

In php the main part is you will have to receive byte array to save as file and also you need to return the same byte array data through file_get_contents.

$GLOBALS will return the Byte_Array data posted from client.

If you will read these tutorials, you will get help on byte array on asp and php as well
http://www.motobit.com/help/scptutl/sa301.htm
http://www.sephiroth.it/tutorials/flashPHP/amfphp_bytearray/

Member Avatar
Dagar.pp
Newbie Poster
1 post since Mar 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
1
 

read the file like :-
$byteArr = fread(fopen($_FILES, "r"), filesize($_FILES));

and than wrap the byteArr into base64encode like below :-

base64_encode($byteArr)

This will work surely.

You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: