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条)

报告相同问题?

悬赏问题

  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 LiBeAs的带隙等于0.997eV,计算阴离子的N和P
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 来真人,不要ai!matlab有关常微分方程的问题求解决,
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算