uploading files to a website using php?
Started by cdel, May 30 2014 09:15 AM
5 replies to this topic
#1
Posted 30 May 2014 - 09:15 AM
I have been googling around and looking various topics but none really explain how to upload a file from ComputerCraft to my website via PHP, then download it again? all help would be much appreciated
#2
Posted 30 May 2014 - 10:43 AM
Downloading is easy:
I know the theory for uploading, am just going to check it. I'll get back to you.
local download = http.get("http://example.com")
if download then
local contents = download.readAll()
else
error("Um. Couldn't download. Sorry!")
end
I know the theory for uploading, am just going to check it. I'll get back to you.
#3
Posted 30 May 2014 - 12:54 PM
SquidDev, on 30 May 2014 - 10:43 AM, said:
Downloading is easy:
I know the theory for uploading, am just going to check it. I'll get back to you.
local download = http.get("http://example.com")
if download then
local contents = download.readAll()
else
error("Um. Couldn't download. Sorry!")
end
I know the theory for uploading, am just going to check it. I'll get back to you.
thanks!
#4
Posted 30 May 2014 - 01:53 PM
To post your file using POST request you would use http.post(url, post_data):
local response = http.post("http://www.example.com", "my=secret&post=data")
if response then
print(response.readAll())
response.close() --// Don't forget to close the handle!
else
print("Cannot connect to the website")
end
Edited by MKlegoman357, 30 May 2014 - 01:53 PM.
#5
Posted 30 May 2014 - 02:12 PM
MKlegoman357, on 30 May 2014 - 01:53 PM, said:
To post your file using POST request you would use http.post(url, post_data):
local response = http.post("http://www.example.com", "my=secret&post=data")
if response then
print(response.readAll())
response.close() --// Don't forget to close the handle!
else
print("Cannot connect to the website")
end
He wants to do file upload (I think). These means you need to do more complex stuff with sending the data. I guess if you have control of the server - you could just read from post but bits of me feel that using multipart/form-data is better. *Sigh*
Edited by SquidDev, 30 May 2014 - 02:17 PM.
#6
Posted 31 May 2014 - 03:49 AM
SquidDev, on 30 May 2014 - 02:12 PM, said:
MKlegoman357, on 30 May 2014 - 01:53 PM, said:
To post your file using POST request you would use http.post(url, post_data):
local response = http.post("http://www.example.com", "my=secret&post=data")
if response then
print(response.readAll())
response.close() --// Don't forget to close the handle!
else
print("Cannot connect to the website")
end
He wants to do file upload (I think). These means you need to do more complex stuff with sending the data. I guess if you have control of the server - you could just read from post but bits of me feel that using multipart/form-data is better. *Sigh*
File upload is in my priority, although when files are uploaded I am wanting them to retain the same name?
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users











