Page 1 of 1

Upload file Livecode PHP

Posted: Thu Feb 15, 2024 3:11 pm
by link76
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!

Re: Upload file Livecode PHP

Posted: Fri Feb 16, 2024 9:20 am
by Zax
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.

Re: Upload file Livecode PHP

Posted: Sat Feb 17, 2024 5:47 pm
by FourthWorld
@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?