php 如何通过php中的网络服务发送/获取文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1696542/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 03:32:38  来源:igfitidea点击:

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

phpweb-servicesfile

提问by Haim Evgi

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

这可能吗 ?发送文件的正确方法是什么?

thanks

谢谢

回答by RageZ

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.

我不希望您的网络服务上传/下载文件。无论如何,您可以使用 curl( http://fr.php.net/curl) 从其他网络服务器上传/下载文件。

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.

要从用户那里将一些文件上传到网络服务,它与从表单中获取它几乎相同,请使用超全局变量:$_FILES ( doc) 来获取上传文件。

for uploading from php to a webservice

用于从 php 上传到网络服务

$fullflepath = 'C:\temp\test.jpg';
$upload_url = 'http://www.example.com/uploadtarget.php';
$params = array(
 'photo'=>"@$fullfilepath",
 'title'=>$title
);  

$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);
curl_close($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

PS:抱歉,由于某些原因,stackoverflow 不喜欢创建...的链接,$_FILES所以我已经链接了 superglobals 页面

回答by Asap

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

你使用这个基于 nusoap 的 php 程序:http://biclim.com/WSClients.action

回答by Jydipsinh Parmar

Hello Here Example Image upload

你好这里示例图片上传

<?php



$path="aa/";// Set your path to image upload
if(!is_dir($path)){
mkdir($path);
}
$roomPhotoList = $_POST['image'];
$random_digit=date('Y_m_d_h_i_s');
$filename=$random_digit.'.jpg';
$decoded=base64_decode($roomPhotoList);
file_put_contents($path.$filename,$decoded);

?>

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

它可以是 ios 和 android 的 php 中的快速图像上传代码

回答by Rajat Talwar

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=8It was really helpful to debug serverside code.

你可以调试你的PHP服务的响应,并使用这个应用程序从iphone检查文件上传- http://itunes.apple.com/us/app/rest-client/id503860664?ls=1&mt=8这是真的很有帮助调试服务器端代码。