douzai1074 2012-12-04 17:26
浏览 85
已采纳

如何使用box.net API上传文件?

Form last 2 days i am trying to fix a issue of uploading a file in Box.net using php.

I have gone through Box.net API Documentation and copied the sample code they have given, the code that they have given- uploads file perfectly, But it redirects to that page where server response is printed(XML response).

I do not want to show user such screen, instead i would like to read those data and based on that response, display message of mine.

I have edited my code as per the guidance given by @GBD, now i am facing another issue.

The file I select does not upload , Instead it uploads some .tmp file. And when i hard code the file path in $_POST['new_file1'] it successfully uploads correct file. the file path i get is some thing like this C:\wamp\tmp\php1A.tmp not actual file path, when i echo $_FILES['new_file1']['tmp_name'].

Can any one tell me how can i get the file path from $_FILES ? So that i can pass it to $post

Following is my code:

<?php
$upload_url = 'https://upload.box.net/api/1.0/upload/i9g1fmnnddfdr4739sxvbpXXXXXXXX/480416060';
$tmpfile = $_FILES['new_file1']['tmp_name'];
$filename = basename($_FILES['new_file1']['name']);
$_POST['new_file1'] = '@'.$tmpfile;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $upload_url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $_POST); 
$response = curl_exec($ch);
curl_close($ch);
echo $response;
?>
<form action=""
  enctype="multipart/form-data" accept-charset="utf-8" method="POST">
<input type="file" name="new_file1" />
<input type="text" name="share" value="1" />
<input type="submit" name="upload_files" value="Upload File" />
</form>

Please help me out.

Thanks in advance.

  • 写回答

1条回答 默认 最新

  • dtwupu6414 2012-12-04 17:49
    关注

    Try

    <?php
    
    $tmpfile = $_FILES['new_file1']['tmp_name'];
    $filename = basename($_FILES['new_file1']['name']);
    
    $_POST['new_file1'] = '@'.$tmpfile;
    
    $upload_url = 'https://upload.box.net/api/1.0/upload/i9g1fmnnddfdr4739sxvbpXXXXXXXX/480416060';
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $upload_url);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_HEADER, true);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $_POST); 
    $response = curl_exec($ch);
    curl_close($ch);
    echo $response;
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 phython如何实现以下功能?查找同一用户名的消费金额合并—
  • ¥15 孟德尔随机化怎样画共定位分析图
  • ¥18 模拟电路问题解答有偿速度
  • ¥15 CST仿真别人的模型结果仿真结果S参数完全不对
  • ¥15 误删注册表文件致win10无法开启
  • ¥15 请问在阿里云服务器中怎么利用数据库制作网站
  • ¥60 ESP32怎么烧录自启动程序
  • ¥50 html2canvas超出滚动条不显示
  • ¥15 java业务性能问题求解(sql,业务设计相关)
  • ¥15 52810 尾椎c三个a 写蓝牙地址