Home » Php » how to send / get files via web-services in php

how to send / get files via web-services in php

Posted by: admin July 12, 2020 Leave a comment


is this possible ?
what is the correct way to send files ?


How to&Answers:

I don’t if you want your webservice to upload/download files. Anyway you can use curl(http://fr.php.net/curl ) to upload/download file from other webserver.

To get some file uploaded to the webservice from the user it’s pretty much the same as gettings it from a form, please use the superglobal variable:$_FILES (doc) to get upload files.

for uploading from php to a webservice

$fullflepath = 'C:\temp\test.jpg';
$upload_url = 'http://www.example.com/uploadtarget.php';
$params = array(

$ch = curl_init();
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_URL, $upload_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
$response = curl_exec($ch);

the webservice to get a file

$uploads_dir = '/uploads';
foreach ($_FILES["photo"]["error"] as $key => $error) {
    if ($error == UPLOAD_ERR_OK) {
        $tmp_name = $_FILES["photo"]["tmp_name"][$key];
        $name = $_FILES["photo"]["name"][$key];
        move_uploaded_file($tmp_name, "$uploads_dir/$name");

PS: sorry for some reason stackoverflow doesn’t like to make a link of $_FILES … so I have linked the superglobals page instead


You use this php program based on nusoap : http://biclim.com/WSClients.action


You can debug the response of your php service and check the file upload from iphone using this app – http://itunes.apple.com/us/app/rest-client/id503860664?ls=1&mt=8
It was really helpful to debug serverside code.


Hello Here Example Image upload


$path="aa/";// Set your path to image upload
$roomPhotoList = $_POST['image'];


it can be quick image upload code in php for ios and android