如果您希望您的web服务上传/下载文件,我不会.无论如何,你可以使用curl(
http://fr.php.net/curl)从其他网络服务器上传/下载文件.
要将一些文件从用户上传到webservice,它几乎与从表单中获取文件一样,请使用超全局变量:$_ FILES(doc)来获取上传文件.
$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,CURLOPT_POSTFIELDS,$params); $response = curl_exec($ch); curl_close($ch);
$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:抱歉由于某种原因stackoverflow不喜欢建立$_FILES的链接…所以我已经链接了superglobals页面而不是