This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
cdel's profile picture

uploading files to a website using php?

Started by cdel, 30 May 2014 - 08:15 AM
cdel #1
Posted 30 May 2014 - 10: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 :)/>
SquidDev #2
Posted 30 May 2014 - 11:43 AM
Downloading is easy:


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.
cdel #3
Posted 30 May 2014 - 01:54 PM
Downloading is easy:


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! :D/>
MKlegoman357 #4
Posted 30 May 2014 - 02: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 on 30 May 2014 - 12:53 PM
SquidDev #5
Posted 30 May 2014 - 03:12 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

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 on 30 May 2014 - 01:17 PM
cdel #6
Posted 31 May 2014 - 04:49 AM
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?