Solved

how to send a multipart post (to send images) as a soap packet ?

Posted on 2010-09-02
3
957 Views
Last Modified: 2013-11-18
Hi Everyone,

I want to upload images to some server using multipart post request. I am using PHP/cURL to send soap request envelopes

Any help would be very appreciated.

Amjad
0
Comment
Question by:sigmatec_pk
  • 2
3 Comments
 
LVL 6

Expert Comment

by:youssefomar
ID: 33603332
Here is a sample of uploading 2 images, hopefully it will help:

You need to files, one to select the images ( select.html ) , and the other to upload them ( uploader.php )

// select.html
<html>

<bidy>
<form enctype="multipart/form-data" action="uploader.php" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="100000" />
Choose a files to upload:
<br/><input name="uploadedfile1" type="file" />
<br/><input name="uploadedfile2" type="file" />

<br/><input type="submit" value="Upload File" />
</form>
</body>
</html>




// uploader.php :
<?
$target_path = "/cb/web/htdocs/fileTest/uploads/";

for($i=1; $i<=2; $i++){
   $target_path = $target_path . basename( $_FILES['uploadedfile'.$i]['name']);
   if(move_uploaded_file($_FILES['uploadedfile'.$i]['tmp_name'], $target_path)) {
      echo "The file ".  basename( $_FILES['uploadedfile'.$i]['name'])." has been uploaded";
   }else{
      echo "There was an error uploading the file, please try again!";
   }
}

?>

Open in new window

0
 
LVL 6

Expert Comment

by:youssefomar
ID: 33603351
a problem with the php code, use this one:

// uploader.php :
<?
$target = "/cb/web/htdocs/fileTest/uploads/";

for($i=1; $i<=2; $i++){
   $target_path = $target . basename( $_FILES['uploadedfile'.$i]['name']);
   if(move_uploaded_file($_FILES['uploadedfile'.$i]['tmp_name'], $target_path)) {
      echo "The file ".  basename( $_FILES['uploadedfile'.$i]['name'])." has been uploaded";
   }else{
      echo "There was an error uploading the file, please try again!";
   }
}

?>

Open in new window

0
 

Accepted Solution

by:
sigmatec_pk earned 0 total points
ID: 33620601

<?php 
$docurl = curl_init(); 
curl_setopt($docurl, CURLOPT_SSL_VERIFYPEER, false); 
curl_setopt($docurl, CURLOPT_URL, "http://site.com/upload.php"); 
curl_setopt($docurl, CURLOPT_VERBOSE, 1); 
curl_setopt($docurl, CURLOPT_HEADER, 1); 
curl_setopt($docurl, CURLOPT_POST, 1); 
curl_setopt($docurl, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt($docurl, CURLOPT_FOLLOWLOCATION, 1); 
curl_setopt($docurl, CURLOPT_POSTFIELDS, array("userfile"=>"{@picture.JPG}")); 
$webpage = curl_exec($docurl); 
echo "$webpage"; 
curl_close($docurl); 
?> 

Open in new window

0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question