Uploading to server via PHP form

Bringing the internet highway into your project? Building FTP, HTTP, email, chat or other client solutions?

Moderators: Klaus, FourthWorld, heatherlaine, robinmiller, kevinmiller

Post Reply
cbarnhart
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 48
Joined: Mon May 07, 2012 2:10 pm

Uploading to server via PHP form

Post by cbarnhart » Tue Mar 25, 2014 5:41 pm

There are numerous post in regards to uploading via a web form but most are CGI and/or Livecode Server. I am not using Livecode server so I have been struggling to create an upload solution for photos from all mobile systems including android. I have a PHP form now working.
UploadPHP.zip
(597 Bytes) Downloaded 150 times
I tried to adapt Simon's code in post -http://forums.runrev.com/viewtopic.php?f=8&t=19144, but either this will not work with PHP or I am just doing something seriously wrong.

I am at a dead end...anyone have any ideas what the LiveCode App end of this should look like to feed this web form?

cbarnhart
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 48
Joined: Mon May 07, 2012 2:10 pm

Re: Uploading to server via PHP form

Post by cbarnhart » Tue Mar 25, 2014 6:21 pm

Sorry forgot to add what I have so far -

Code: Select all

local tData,tPic,tName

on mouseUp
   put "" into fld 1
   if the environment is "mobile" then
      set the vis of the templateImage to false
      mobilePickPhoto "library"
      put the last image into tPic
      put "mobUp.jpg" into tName --someone fix this so the user can put there own filename in
   else --desktop testing
      answer file "Select a file to upload:" with filter "JPEGs,*.jpg"
      put url ("binfile:"& it) into tPic

      put tPic into field "bin" --just for me
      
      set itemDel to "/"
      put the last item of it into tName
      
   end if
   put buildIt() into tData 
   put tData into field "build" --just for me
   post tData to URL "http://www.mysite.com/upload_file.php" --where did you put the file?
   put it into fld 1 
   set the httpHeaders to empty
   set  the vscroll of fld 1 to 1000
end mouseUp

function buildIt
   put "--__Part__" & crlf into tData
   put "Content-Disposition: form-data; name=" & quote & "photo" & quote & "; filename=" & quote & tName & quote & crlf after tData
   put "Content-Type: image/jpg" & crlf after tData
   put "Content-Transfer-Encoding: binary" & crlf & crlf after tData
   put tPic & crlf after tData
   put "--__Part__--" after tData
   put "Content-Type: multipart/form-data; boundary=" & quote & "__Part__" & quote into theHeader
   set the httpHeaders to theHeader
   return tData
end buildIt

cbarnhart
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 48
Joined: Mon May 07, 2012 2:10 pm

Re: Uploading to server via PHP form

Post by cbarnhart » Fri Mar 28, 2014 4:41 pm

Figured it out. It was all in the header

Code: Select all

   put "Content-Disposition: form-data; name=" & quote &"file"& quote & "; fileName=" & quote & tName & quote & crlf after tData
Now works like a dream

Adrien
Posts: 26
Joined: Fri Jan 09, 2015 9:55 am

Re: Uploading to server via PHP form

Post by Adrien » Sat Mar 28, 2015 4:24 pm

Hello,

Thanks for posting this solution - works great on desktop (Mac at least).

However, a post or put call when httpHeaders is set will crash my iOS app.
If I leave httpHeaders empty, the php script will go on but of course no file will be uploaded.

iOS 8.1.3, LC 7.0.0 commercial.

I reported it as a bug (Bug 15102) but maybe I can get more info here (not sure if QA works the weekends..).


Thanks :D

Post Reply

Return to “Internet”