如何将App Inventor文件发送到给定位置

时间:2016-04-23 18:44:24

标签: php android app-inventor

我正在关注如何从App Inventor应用程序中将文件发布到php服务器的Taifun教程(https://puravidaapps.com/postfile.php)。

我想知道如何做同样的事情,但同时将它们移动到一个给定的位置,就像一个以发布它的人命名的新创建的文件夹。

1 个答案:

答案 0 :(得分:1)

如果我理解你的问题,我在项目中也需要相同的功能,这就是我所做的,

这是fileUpload.php文件

<?php
$target_path="uploads/".$_POST['username']."/";
if (!is_dir($target_path)) 
// is_dir - tells whether the filename is a directory
{
    //mkdir - tells that need to create a directory
    mkdir($target_path);
}
$target_path=$target_path.basename($_FILES['image']['name']);
try {
    //throw exception if can't move the file
    if (!move_uploaded_file($_FILES['image']['tmp_name'], $target_path)) {
        throw new Exception('Could not move file');
    }
    echo $target_path;
} catch (Exception $e) {
    die('Upload Failed: ' . $e->getMessage());
}
?>

虽然这是从浏览器测试上传的文件,

<html>
    <head>
        <title>File Upload Form</title>
    </head>
    <body>
        <form enctype="multipart/form-data" action="fileUpload.php" method="POST">            
            <br/>Choose a file to upload: <br/><input name="image" type="file" /><br />
            User Name: <input type="text" name="username"/>
            <input type="submit" value="Upload File" />
        </form>

    </body>
</html>

我认为你可以很容易地弄清楚如何从android处理这个问题。

希望这有帮助! :)