Code: Select all
Procedure UploadFileCallback(Success, Filename.s, Result.s)
Debug "UploadFileCallback('" + Filename + "'):"
Debug Success
Debug Result
Debug "----------------------------"
EndProcedure
Procedure UploadFile(URL.s, File, Callback)
Protected FileToUpload
Protected Filename.s
! v_filetoupload = spider.file.objects.Get(v_file).localFile;
! v_filename = v_filetoupload.name;
Debug "Uploading " + Filename + "..."
! var formData = new FormData();
! formData.append('file', v_filetoupload);
! $.ajax({
! url: v_url,
! data: formData,
! contentType: false,
! processData: false,
! method: 'POST',
! type: 'POST',
! success: function(response) { v_callback(true, v_filename, response) },
! error: function(xhr, status, error) { v_callback(false, v_filename, xhr.statusText) },
! });
EndProcedure
Procedure ReadCallback(Status, Filename.s, File, Size)
If Status = #PB_Status_Loaded
Debug "File: " + Filename.s + " / Size: " + Size + " bytes"
UploadFile("[YourUpload].php", File, @UploadFileCallback()) ; <-- adjust the path to your upload-component!
CloseFile(File)
ElseIf Status = #PB_Status_Error
Debug "Error when loading the file: " + Filename$
EndIf
EndProcedure
Procedure OpenFileRequesterCallback()
While NextSelectedFile()
ReadFile(#PB_Any, SelectedFileID(), @ReadCallback(), #PB_LocalFile)
Wend
EndProcedure
Procedure ChooseFileEvent()
OpenFileRequester("*.*", @OpenFileRequesterCallback(), #PB_Requester_MultiSelection)
EndProcedure
OpenWindow(0, 0, 0, 300, 50, "Upload file example", #PB_Window_ScreenCentered)
ButtonGadget(0, 10, 10, 280, 30, "Choose file(s)...")
BindGadgetEvent(0, @ChooseFileEvent())
Code: Select all
<?php
header("Access-Control-Allow-Origin: *");
if(!empty($_FILES['file'])) {
echo "The file ". basename( $_FILES['file']['name']). " has been uploaded";
}