【问题标题】:File Upload Issue Android WebView文件上传问题 Android WebView
【发布时间】:2021-12-10 23:27:39
【问题描述】:

如何使用 PHP 将图像从 android WebView 上传到 MySQL 数据库?我已经实现了一个文件选择器,用于从我们的设备中选择图像。

【问题讨论】:

    标签: php android mysql webview android-webview


    【解决方案1】:

    您可以查看此演示示例 HTML

    <html>
    <head>
    <title>File Upload</title>
    </head>
    <body>
    <form action="upload.php" method="post" enctype="multipart/form-data">
    <input type="file" name="file" />
    <button type="submit" name="upload">upload</button>
    </form>
    </body>
    </html>
    

    PHP 代码:

    <?php
    include_once 'database.php';
    if(isset($_POST['upload']))
    {   
         
     $file = rand(1000,100000)."-".$_FILES['file']['name'];
        $file_loc = $_FILES['file']['tmp_name'];
     $file_size = $_FILES['file']['size'];
     $file_type = $_FILES['file']['type'];
     $folder="upload/";
     
     /* new file size in KB */
     $new_size = $file_size/1024;  
     /* new file size in KB */
     
     /* make file name in lower case */
     $new_file_name = strtolower($file);
     /* make file name in lower case */
     
     $final_file=str_replace(' ','-',$new_file_name);
     
     if(move_uploaded_file($file_loc,$folder.$final_file))
     {
      $sql="INSERT INTO image(file,type,size) VALUES('$final_file','$file_type','$new_size')";
      mysqli_query($conn,$sql);
      
     
      echo "File sucessfully upload";
            
      
     }
     else
     {
      
      echo "Error.Please try again";
            
            }
        }
    ?>
    

    谢谢

    【讨论】:

      猜你喜欢
      • 2013-01-22
      • 2012-07-28
      • 1970-01-01
      • 2012-06-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多