0

Im looking for clear answer for beginners how to configure apache2 sever under linux to have capabilities to send/ recive files via PUT method and in the meantime how to write a script in PHP to have possibilities to capture data and save them into spec. folder. I have read some off answers which have been given on this forum but none of them gave me 100% possibilite to understand how to successfully reach my objectives

I have client under 192.168.1.10 which send event.json file via HTTP PUT method Server is at 192.168.1.50 linux PC (apache2 server running under)

Maybe there is different way to achieve my goal ?

Hello so I have written some code (basic)

/var/www/html# index.html

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>JSON_read</title>
</head>
<body>
<form method="put"
      action="http://192.168.1.50/jej.php">
</form>
</body>
</html>

jej.php

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">  
<title>JSON_read results</title>
</head>
<body>
<p>
<?php
$value = @file_get_contents('http://192.168.1.50/events.json');
var_dump(json_decode($value));
var_dump(json_decode($value, true));
?>
<p>
</body> 
</html>

and I did cmd : curl -X PUT -d arg=val -d arg2=val2 127.0.0.1:80

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"> 
<html><head> 
<title>405 Method Not Allowed</title>
</head><body>
<h1>Method Not Allowed</h1>
<p>The requested method PUT is not allowed for the URL /index.html.</p>
<hr>
<address>Apache/2.4.18 (Ubuntu) Server at 127.0.0.1 Port 80</address>
</body></html>

and other : curl -X PUT -d arg=val -d arg2=val2 192.168.1.50:80

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head> 
<title>405 Method Not Allowed</title>
</head><body>
<h1>Method Not Allowed</h1>
<p>The requested method PUT is not allowed for the URL /index.html.</p>
<hr>
<address>Apache/2.4.18 (Ubuntu) Server at 192.168.1.50 Port 80</address>
</body></html>

Question is => 1. whether PUT method is correctly implemented ? Do I have to enable something in apache ? 2. whether my php.sh was correctly written to read JSON data (which will be send from client to the server) and if all JSON data would be visibile on server page ?

Pretbc
  • 11
  • 4
  • 1
    Apache has no issues handling PUT requests - no configuration is necessary - and [all major browsers now support it](https://stackoverflow.com/questions/165779/are-the-put-delete-head-etc-methods-available-in-most-web-browsers). What, specifically, are you having trouble with? – ceejayoz Oct 30 '17 at 14:12
  • from above when client sends data to server I have problem to capture data - > i need php script nevertheless when I type: curl -X PUT -d arg=val -d arg2=val2 127.0.0.1:80 I've get - request method PUT is not allowed for URL /index.html – Pretbc Oct 30 '17 at 14:16
  • 1
    Yeah, you can't `PUT` to a HTML file. You'll need to `PUT` to some sort of server-side script written in something like PHP that's set up to handle the request. – ceejayoz Oct 30 '17 at 14:18
  • So Im looking a help in that topic bcoz It is hard for me to understand how it's working. How to config apache2 - php script to reach an finale goal – Pretbc Oct 30 '17 at 14:21
  • 1
    [The manual](http://php.net/manual/en/features.file-upload.put-method.php) has example on how to do exactly this. You can also verify the request method by checking whether `$_SERVER['REQUEST_METHOD'] == 'PUT'` – apokryfos Oct 30 '17 at 14:24
  • Should just rewrite example to my PC and it would works ? – Pretbc Oct 30 '17 at 14:26
  • Maybe, that depends on your "rewrite". Give it a try, then come back with *specific* problems you encounter, including code and any errors you encounter. – ceejayoz Oct 30 '17 at 14:28
  • please check EDIT post – Pretbc Nov 06 '17 at 10:40

0 Answers0