如何在 post 变量中使用 wget 发布文件内容? [英] How to post a file content with wget in a post variable?

查看:35
本文介绍了如何在 post 变量中使用 wget 发布文件内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a very simple php script :

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

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

I'm trying to post the content of a local file (unix) using wget.

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

似乎发布但未附加到任何字段".

seems to post but don't attach to any 'field'.

我该怎么做?

推荐答案

你真的需要 wget 吗?实际上,在阅读 wget 手册页时... wget 无法执行您希望它执行的操作.

Do you really need wget? Actually upon reading the wget man page ... wget can't do what you want it to do.

你可以使用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 变量中使用 wget 发布文件内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆