Upload file Livecode PHP

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
link76
Posts: 99
Joined: Fri Nov 04, 2011 1:52 pm

Upload file Livecode PHP

Post by link76 » Thu Feb 15, 2024 3:11 pm

I would like to upload a pdf file to my server using php as a step.
I created this script in livecode but I can't complete the step in php:

Code: Select all

on mouseUp
   put empty into tFilePath
   answer file "Scegli un file pdf" with type "PDF|pdf"
   if it is not empty then
      put it into tFileToUpload
      set the itemDel to slash
      put the last item of tFileToUpload into tFileName
      put URL("file:" & tFileToUpload) into tFileContents   
      post tFileContents to URL "http://10.6.0.153/geco2/upload.php"
   end if
end mouseUp
PHP

Code: Select all

<?php
  $file = $_FILES['tFileContents'];
  if ($file['error'] == 0) {
    $filename = $file['name'];
    $tmpname = $file['tmp_name'];
    $destination = "uploads/" . $filename;
    if (move_uploaded_file($tmpname, $destination)) {
      echo "uploadComplete";
    } else {
      echo "uploadError";
    }
  } else {
    echo "uploadError";
  }
  ?>
Maybe there is a faster solution but I can't use ftp, thanks for the help!

Zax
Posts: 472
Joined: Mon May 28, 2007 10:12 am
Location: France
Contact:

Re: Upload file Livecode PHP

Post by Zax » Fri Feb 16, 2024 9:20 am

I think you could do that without PHP, using tsNet provided by LC:
https://www.techstrategies.com.au/tsnet ... UploadSync

The data tranfer is synchronous (asynchronous only in the commercial edition) but it doesn't block the UI.

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9842
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Upload file Livecode PHP

Post by FourthWorld » Sat Feb 17, 2024 5:47 pm

@Zax: link76 noted that ftp is not an option for this project.

@link76: what are the symptoms of failure? Any diagnostic info returned from the php script?
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”