Jump to content




uploading files to a website using php?


  • You cannot reply to this topic
5 replies to this topic

#1 cdel

  • Banned
  • 496 posts
  • LocationMelbourne, Australia

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 SquidDev

    Frickin' laser beams | Resident Necromancer

  • Members
  • 1,427 posts
  • LocationDoes anyone put something serious here?

Posted 30 May 2014 - 10: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.

#3 cdel

  • Banned
  • 496 posts
  • LocationMelbourne, Australia

Posted 30 May 2014 - 12:54 PM

View PostSquidDev, on 30 May 2014 - 10:43 AM, said:

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

#4 MKlegoman357

  • Members
  • 1,170 posts
  • LocationKaunas, Lithuania

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 SquidDev

    Frickin' laser beams | Resident Necromancer

  • Members
  • 1,427 posts
  • LocationDoes anyone put something serious here?

Posted 30 May 2014 - 02:12 PM

View PostMKlegoman357, 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 cdel

  • Banned
  • 496 posts
  • LocationMelbourne, Australia

Posted 31 May 2014 - 03:49 AM

View PostSquidDev, on 30 May 2014 - 02:12 PM, said:

View PostMKlegoman357, 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