martedì 26 luglio 2016

Come caricare i file su un server livecode

Livecode può essere utilizzato anche come server al posto di PHP o CGI, vediamo oggi come caricare un file.
Prima di tutto creiamo un normale form web per scegliere e caricare un file:

<html>
 <head></head>
 <body>
  <H1>Upload Form</H1>
   <form enctype="multipart/form-data" action="file_upload_example.lc" method="POST">
    Choose a file to upload: <input name="uploadedfile" type="file" /><br />
    <input type="submit" value="Upload File" />
   </form>
 </body>
</html>


Poi creiamo il file file_upload_example.lc, che servirà per caricare il file.

<html>
 <body> 
  <H1>Uploaded Files</H1>
  <p>
   <?lc
     if $_Files[uploadedfile][error] then
       put "There was an error uploading your file:" && $_Files[uploadedfile][error] & "<br />"
     else
       put $_Files[uploadedfile][name] into tFileName
       put $_Files[uploadedfile][type] into tFileType
       put $_Files[uploadedfile][size] into tFileSize
       put $_Files[uploadedfile][filename] into tFilePath
       put "Your file '" & tFileName & "' was uploaded successfully. It is" && tFileSize && "bytes in size."
     end if
   ?>
</p>
</body>
</html>


Finito.