Solved

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

Posted on 2010-09-02
3
956 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Shoutout to Emily Plummer (http://www.experts-exchange.com/members/eplummer26.html) for giving me this article! She did most of it, I just finished it up and posted it for her :)    Introduction In a previous article (http://www.experts-exchang…
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.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
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)

895 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now