douchuopiao9002 2014-08-21 10:06
浏览 180
已采纳

需要php代码来存储用wget上传的文件

I need to upload file on server from command line. I do next:

wget -d --post-file=links.txt http://bearnova.com/upload_file.php

Here is upload_file.php . Code below doesn't work of course:

<?php
if ($_FILES["file"]["error"] > 0) {
  echo "Error: " . $_FILES["file"]["error"] . "<br>";
} else {
  echo "Upload: " . $_FILES["file"]["name"] . "<br>";
  echo "Type: " . $_FILES["file"]["type"] . "<br>";
  echo "Size: " . ($_FILES["file"]["size"] / 1024) . " kB<br>";
  echo "Stored in: " . $_FILES["file"]["tmp_name"];

  move_uploaded_file($_FILES["file"]["tmp_name"],
  "upload/" . $_FILES["file"]["name"]);
  echo "Stored in: " . "upload/" . $_FILES["file"]["name"];

}
?>

Wget does an HTTP POST to send file. I've also heard about $_POST, $HTTP_RAW_POST_DATA and file_get_contents(php://input) I'm not a php guy at all. So could someone please help me to get a valid solution? Thanks.

  • 写回答

4条回答 默认 最新

  • duanpang1987 2014-08-21 11:23
    关注

    I get contents of file this way:

    <?php $postdata = file_get_contents("php://input"); ?>
    

    $HTTP_RAW_POST_DATA - the same as the above but depends on php.ini (empty in my case)

    I need to store it in file on server side and it seems that filename was not sent either but it should be not a big deal.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度