Mission complete!
I’m posting the only code missing (although its available in Scott’s archive link)
<?php
$target_path = "uploadfolder/";
$target_path = $target_path . basename( $_FILES['myfile']['name']);
if(move_uploaded_file($_FILES['myfile']['tmp_name'], $target_path)) {
$src = $target_path;
$dst = 'uploadfolder/decoded_'.basename( $_FILES['myfile']['name']);
base64file_decode( $src, $dst );
echo "The file ". basename( $_FILES['myfile']['name']). " has been uploaded";
} else{
echo "There was an error uploading the file, please try again!";
}
function base64file_decode( $inputfile, $outputfile ) {
/* read data (binary) */
$ifp = fopen( $inputfile, "rb" );
$srcData = fread( $ifp, filesize( $inputfile ) );
fclose( $ifp );
/* encode & write data (binary) */
$ifp = fopen( $outputfile, "wb" );
fwrite( $ifp, base64_decode( $srcData ) );
fclose( $ifp );
/* return output filename */
return( $outputfile );
}
?>
Also a few notes
The image file is base64 encoded.
Two images are getting upload, encoded and decoded version.
If you need only the decoded version replace this:
$dst = ‘uploadfolder/decoded_’.basename( $_FILES[‘myfile’][‘name’]);
with this:
$dst = ‘uploadfolder/’.basename( $_FILES[‘myfile’][‘name’]);
You can change the upload file size limit on your server by editing php.ini.
Everything works great on simulator console but on android you also need to create and xml folder in androidresources/res folder and create file network_security_config.xml with this code:
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<domain-config cleartextTrafficPermitted="true">
<domain includeSubdomains="true">domainname.com</domain>
</domain-config>
</network-security-config>
Last but not least I didn’t find a way to upload an image from a file that was already inside the apk when built.
There are a few solutions here:
I tried the easiest workaround by renaming the file but did’t work for me.
The truth is that didn’t try much (didn’t even read all the posts
because all I need is to upload files from image gallery / camera.
The most important thing is that Solar2D proved once again that is an amazing tool and you can do (almost) anything you want.
@Scott_Harrison thanks again your help and @vlads keep up the good work ![]()