Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

php

wget

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 ?

like image 247
Disco Avatar asked Sep 30 '12 13:09

Disco


1 Answers

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);
?>
like image 129
Igor Serko Avatar answered Oct 13 '22 15:10

Igor Serko