I've tried using http.post but it seems you have to use PHP to handle the uploaded text and save it into a file.
Now my question is how you can do this, I don't know PHP and would be grateful to receive some help about it.
- Hellkid98
if(isset($_POST['variable'])){ //if the post value 'variable' is set
$f = "file location here" //where on the server to save the file
if (!file_exists($f)){ //if file already exists
$handle = fopen($f, 'w'); //opens the file from the first charater
if(!fwrite($handle,stripslashes($_POST['variable']))){ //writes to the file removeing the php escapes and will run code is not running.
//this code will run if the file can not be written
}
}
http.post("<url>", "Hello World")
Anyway, Thanks :D/> http.post("<url>","variable="..variable or "hello world")
That should do the trickThe file doesn't change :/
No.
You need to declare the variable first..
(you need to post the "variable" variable on the website..That should do the trickhttp.post("<url>","variable="..variable or "hello world")
EDIT:
Oh wait!!
if you want to send the whole text file via CC, then you have to use fs.open, and then read all lines, and then post that as a variable
Well I tried deleting the file also, And it doesn't even create a new one .-.The file doesn't change :/
If you want it to override an existing file you will have to remove the conditional: "if(!file_exists($f)){" as it checks to see if the file doesn't exist.
Well I tried deleting the file also, And it doesn't even create a new one .-.The file doesn't change :/
If you want it to override an existing file you will have to remove the conditional: "if(!file_exists($f)){" as it checks to see if the file doesn't exist.
var = "hello there!"
encodedVar = textutils.urlEncode(var)
http.post("http://url", "var=" .. encodedVar)
Which url? In the computercraft program or in the PHP file?And add this to your url '?variable=…'
if(isset($_GET['variable'])){
$f = "highscoresData" //where on the server to save the file
if (!file_exists($f)){
$handle = fopen($f, 'w'); //opens the file from the first charater
if(!fwrite($handle,stripslashes($_POST['variable']))){ //writes to the file removeing the php escapes and will run code is not running.
//this code will run if the file can not be written
}
local function post( data )
local encData = textutils.urlEncode( data )
local tryPost = http.post("http://www.hellkid98.eu.pn/Lasers/upload.php?variable=...", "variable=" .. encData)
if tryPost then
return true
else
return false
end
end
http.get("http://www.example.com/test.php?variable=" .. textutils.urlEncode("hello there!"))
And use the $_GET superglobal in PHP. Eg:
if (isset($_GET["variable"])) {
echo $_GET["variable"];
}
http.post("http://www.example.com/test.php", "variable=" .. textutils.urlEncode("hello there!"))
And use the $_POST superglobal in PHP. Eg:
if (isset($_POST["variable"])) {
echo $_POST["variable"];
}
local fileContents = "hello there!"
local result = http.post("http://www.example.com/upload.php", "content=" .. textutils.urlEncode(fileContents))
local resultContent = result.readAll()
result.close()
if resultContent:find("true") then
print("yay!")
else
print("oh :(/>/>/>/>")
end
$filename = "test.txt";
if (isset($_POST["content"])) {
if (!file_exists($filename)) {
// file_put_contents does the same thing as opening the file, writing to it, and closing it. It's just easier to type and returns false on error
if (file_put_contents($filename, $_POST["content"]) !== false) {
exit("true\n");
}
}
}
exit("nope\n");