【问题标题】:How to post a file content with wget in a post variable?如何在 post 变量中使用 wget 发布文件内容?
【发布时间】:2012-09-30 13:52:42
【问题描述】:

我有一个非常简单的 php 脚本:

<?
  $received:file = $_POST['file'];
  // do something with it
?>

我正在尝试使用 wget 发布本地文件 (unix) 的内容。

wget --post-data='operation=upload' --post-file myfile 

似乎发布但未附加到任何“字段”。

我该怎么做?

【问题讨论】:

  • 如果您阅读manual,您会看到它说wget 不支持文件上传。请改用 curl 之类的其他内容。 --post-data--post-file 也不能共存。只应指定其中之一。
  • Post request with Wget?的可能重复

标签: php wget


【解决方案1】:

你真的需要wget吗?实际上在阅读 wget 手册页后...... wget 不能做你想做的事。

你可以使用curl

curl -F"operation=upload" -F"file=@myfile" http://localhost:9000/index.php

获取文件:

<?php
$uploadfile = '/tmp/' . basename($_FILES['file']['name']);
move_uploaded_file($_FILES['file']['tmp_name'], $uploadfile);
$content = file_get_contents($uploadfile);
?>

【讨论】:

  • 对;我没想到卷曲……我试过了;但它似乎没有发布文件。
  • 文件内容在哪里发布?在 post 变量中?
  • 那么 myfile 必须存在于您的当前目录中...如果您仍然认为它不起作用,您可以使用ngrep 来监听网络请求...例如。 ngrep -d lo -c 120 端口 9000
  • 实际上 ... Tony 说得对 ... 它被发布到 $_FILES ... 请参阅 php.net/manual/en/features.file-upload.php ... 所以 $_FILES['file'] 就是您要查找的内容.
  • 对于多个文件,使用:-F"file1=@myfile1" -F"file2=@myfile2" 等等。 (file1, file2 可以是任何东西。您将其读取为:$_FILES["file1"] 和 $_FILES["file2"] 或者只是做一个 foreach($_FILES ...)
猜你喜欢
  • 2012-01-25
  • 1970-01-01
  • 2011-11-21
  • 1970-01-01
  • 2014-02-03
  • 2013-04-27
  • 1970-01-01
  • 2018-12-24
  • 2023-01-13
相关资源
最近更新 更多