How to post a file content with wget in a post variable?

陌路散爱 提交于 2019-12-19 07:58:56

问题


I have a very simple php script :

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

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'.

How can I do that ?


回答1:


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

You can use curl

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

Get the file with:

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


来源:https://stackoverflow.com/questions/12661759/how-to-post-a-file-content-with-wget-in-a-post-variable

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!