By the way, I tried to manually edit a file I have in Docs. I opened it with Google Sheets, edited it (Google Sheets seems to save it automatically because the word "saving" appears, and then I can't find the save option anywhere). I went to reopen it and found it exactly as it was before the edit. Yes, I really think it's Android 14 that's having problems.
And even with these two blocks, it doesn't give any results, nor any errors.
If I set mfile1 to legacy (the only option, and on Android 14, it seems that legacy isn't valid), it tells me to set the app for permissions (the program denies permissions, and in the app settings, there's no option to authorize reading and writing, only video and audio).
You are trying to read a non media file, which is not owned by your app
See here Some basics on Android storage system
You have to use SAF to do this
Taifun
prova.aia (38.7 KB)
Enough, I give up, I resign myself to not understanding what's wrong.
If you want, take a look, I can't take it anymore
*UPLOAD*
*<?php *
*if (isset($_FILES['file'])) {*
* $target_dir = "storage/emulated/0/Android/data/edu.mit.appinventor.aicompanion3/files/"; //*emphasized text**
* $target_file = $target_dir . basename($_FILES["file"]["name"]);*
* // Sposta il file dalla cartella temporanea alla destinazione finale*
* if (move_uploaded_file($_FILES["file"]["tmp_name"], $target_file)) {*
* echo "Il file ". htmlspecialchars( basename( $_FILES["file"]["name"])). " è stato caricato con successo.";*
* } else {*
* echo "Si è verificato un errore durante il caricamento del file.";*
* }*
*} else {*
* echo "Nessun file ricevuto.";*
*}*
*?>*
*download*
<?php
// Controlla se è stato specificato un nome di file
$_GET['filename']
if (isset($_GET['filename'])) {
$filename = $_GET['filename'];
$file_path = "//ufo1.byethost14.com/" . $filename;
if (file_exists($file_path)) {
// Imposta gli header per forzare il download
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="'.basename($file_path).'"');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($file_path));
// Legge il file e lo invia al browser
readfile($file_path);
exit;
} else {
http_response_code(404);
echo "Il file non è stato trovato.";
}
} else {
echo "Nessun nome di file specificato.";
}
?>
It looks like this is another try to upload a file to your server
I moved your 2 posts into the correct thread
If you are asking for help, I recommend you to make it as easy for others to be able to help you ...
You probably will get more feedback then...
which means in your case post a screenshot of your relevant blocks...
Also please explain what exactly happens and what you want to happen instead. In case there is an error message, provide the error number as well as the error text, also providing a screenshot could help.
Be as specific as possible. Take as much effort to describe your issue as you want others to provide a useful answer.
To download the aia file, upload it to App Inventor, open it, do some bug hunting for you, etc... this takes time, and most people will not do that...
Thank you.
See also How to ask a question (open new topic)
Taifun
Trying to push the limits! Snippets, Tutorials and Extensions from Pura Vida Apps by Taifun.
Unfortunately you did not take much effort iin explaining what's going on... anyway. .
-
First of all, asking for read and write permission is only required for older devices < Android 11... just remove these for the moment...
-
you have a lot of experience, so you already heard about naming conventions to make the code more readable not only for you, but also for others trying to help...
For example instead of Button1 you could rename that component to btnDownload to easier understand what that button is about
And Textbox1 could be renaned to txbFilename. .
Do that accordingly for the other components...
So what do you get in Label3 and Label4?
- In the Web1.GotFile event then you are trying to use the File.SaveFile method, which does not make sense. Read more about that method in the documentation Storage
Your file will be downloaded to ASD - the application specific storage inside your app... what you probably want is to copy it from there to shared storage? Can you elaborate?
If yes, try the Copy method from the file component
From scope App
From filename this must be the downloaded filename only without path (for example myImage.jpg)
To scope Legacy
To filename /Download/myImage.jpg
Also it is recommended to do it step by step. . First get the download running, then continue with the upload
Let me recommend to use the php script provided earlier by @TIMAI2 after you got that running, then adjust it to your needs
Taifun
Unfortunately, I discovered that there are limitations on Android 14
even for the download folder.
The same goes for legacy functionality.
Before thinking about aesthetics, I wanted to get to the effectiveness of the app. To find out what the buttons are for, there aren't thousands of blocks. And anyway, there's a "from" label first and a "to" label after. It seemed pretty intuitive.
But on the buttons, it looks like they say download and upload, or am I wrong?
I don't know if you read that labels 3 and 4 are used to store the response from the web got file.
What's wrong with the upload and download .php files?
I'm asking to understand what I'm doing wrong.
upload
<?php
// Check if a file has been uploaded
if (isset($_FILES['file'])) {
$target_dir = "ufo1.byethost14.com/htdocs/"; // Make sure the 'uploads' folder exists and is writable
$target_file = $target_dir . basename($_FILES["file"]["name"]);
// Move the file from the temporary folder to the final destination
if (move_uploaded_file($_FILES["file"]["tmp_name"], $target_file)) {
echo "The file ". htmlspecialchars( basename( $_FILES["file"]["name"])). " was uploaded successfully.";
} else {
echo "An error occurred while uploading the file.";
}
} else {
echo "No file received.";
}
?>
download
<?php
// Check if a file name was specified
$_GET['filename']
if (isset($_GET['filename'])) {
$filename = $_GET['filename'];
$file_path = "//ufo1.byethost14.com/htdocs/" . $filename;
if (file_exists($file_path)) {
// Set headers to force download
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="'.basename($file_path).'"');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($file_path));
// Reads the file and sends it to the browser
readfile($file_path);
exit;
} else {
http_response_code(404);
echo "File not found.";
}
} else {
echo "No file name specified.";
}
?>
purtoppo ho scoperto che su android 14 ci sono limitazioni
anche per la cartella download/
lo stesso dicasi sulla funzionalità legacy
prima di pensare all estetica volevo arrivare all efficacia dell app, per scoprire a cosa servono i pulsanti non sono poi migliaia di blocchi, e comunque prima c'e' un da e dopo c'e' un to , mi sembrava abbastanza intuitivo
ma sui pulsanti mi sembra che ci sia scritto download e upload o sbaglio ?
non so se hai letto che label3 e 4 servirebbero per memorizzare la risposta del web got file
cosa c'e' di sbagliato nei file upload e download . php ?
lo chiedo per capire dove sto sbagliando
upload
<?php
// Controlla se è stato caricato un file
if (isset($_FILES['file'])) {
$target_dir = "ufo1.byethost14.com/htdocs/"; // Assicurati che la cartella 'uploads' esista e sia scrivibile
$target_file = $target_dir . basename($_FILES["file"]["name"]);
// Sposta il file dalla cartella temporanea alla destinazione finale
if (move_uploaded_file($_FILES["file"]["tmp_name"], $target_file)) {
echo "Il file ". htmlspecialchars( basename( $_FILES["file"]["name"])). " è stato caricato con successo.";
} else {
echo "Si è verificato un errore durante il caricamento del file.";
}
} else {
echo "Nessun file ricevuto.";
}
?>
download
<?php
// Controlla se è stato specificato un nome di file
$_GET['filename']
if (isset($_GET['filename'])) {
$filename = $_GET['filename'];
$file_path = "//ufo1.byethost14.com/htdocs/" . $filename;
if (file_exists($file_path)) {
// Imposta gli header per forzare il download
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="'.basename($file_path).'"');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($file_path));
// Legge il file e lo invia al browser
readfile($file_path);
exit;
} else {
http_response_code(404);
echo "Il file non è stato trovato.";
}
} else {
echo "Nessun nome di file specificato.";
}
?>
What should these limitations be?
You could make it easier for others to help, but you are obviously not interested
In your blocks we can't see your button texts
It looks like you are not really interested in getting something to work
I listed 2 main errors in your blocks and suggested to use a php script which is known to work. Also I asked you some questions without getting answers. This makes it impossible for me to continue trying to help
Yes I can see that. What I can't see are the values of these labels after you were doing a test run to find out if there was an error or if the download worked
This is an App Inventor community and not a php community. I can't help you with errors in your php code. So why not
Good luck!
Taifun
Your upload php file looks like it expects multipart/data
. The Web component does not handle multipart/data uploads.
Use one of the two php methods, and the blocks, I provided earlier
You do not need a download.php file, you should be able to download a file on your server directly with its url.
@TIMAI2
There are 2 files, upload and download, it's not a multipart/data.
In the simple examples you linked to, urlname/upload?fname=, I knew that with the web postfile, the php file took its name directly from the post file path and the file name was the last one after the final slash.
But did those examples actually work for you?
Since Android 14 also limits access to documents/ and download/, I used
"storage/emulated/0/Android/data/edu.mit.appinventor.aicompanion3_user"& %40 & mail.com/prova/files/", but I don't know if that's the correct path.
And how do you download a file via its URL?
Yes, I would not be recommending their use otherwise
A download url:
https://ufo1.byethost14.com/myfile.txt
Not correct.
/storage/emulated/0/Android/data/edu.mit.appinventor.aicompanion3/files
Is the absolute path to the ASD when using the companion app.
Do not hard code this into your app. Use the File component to construct your ASD path, so that it uses the correct packageName(name of your app) in the path
i used /storage/emulated/ ecc. same result
The download doesn't give any errors, but it doesn't even give results in labels 3 and 4.
So I don't know if the download works or not because my phone's memory won't show anything beyond data/.
The upload gives the usual 1104 error, and I think it always depends on the path. Since Android 14 also limits access to documents/ and download/, I used what you told me, but I don't know if it's the right path.
<?php
// Simple PHP script to save image file.
$imgDir = "ufo1.byethost14.com/";
$fileName = $_REQUEST['fname'];
$data = file_get_contents('php://input');
$store = file_put_contents($imgDir.$fileName, $data);
if ($store !== false ) {
echo "File $fileName saved to server, $store bytes\n";
} else {
echo "File $fileName not saved\n";
}
?>
<?php
// Simple PHP script to save image file.
$imgDir = "ufo1.byethost14.com/";
$fileName = $_REQUEST['fname'];
$data = file_get_contents('php://input');
$store = file_put_contents($imgDir.$fileName, $data);
if ($store !== false ) {
echo "File $fileName saved to server, $store bytes\n";
} else {
echo "File $fileName not saved\n";
}
?>