duanjiao6711 2017-05-26 16:45
浏览 273
已采纳

如何在URL中传递POST参数

Is it possible to upload images/files by sending the POST or REQUEST, parameters in the URL without HTML content?

I created a PHP file that gets a image from my someone, stores that file into the database, and a in a folder on my computer. It works fine but what I want to do now is remove the html content and only allow someone to send the images/files via the URL. I tried using $_GET but I received a lot of errors. I also researched this and read that only $_POST will work.

Here is my PHP source code with HTML but keep in mind, "I want the page blank and the only way for someone to send the images/files is through URL".

PHP:

if(isset($_POST['submit'])){

    if(@getimagesize($_FILES['image']['tmp_name']) ==FALSE){

        // Select an image
        echo "Please select an image.";
    }
    else{
    // THE PATH TO STORE THE UPLOAD IMAGE
    $target = "images/".basename($_FILES['image']['name']);

    //CONNECT TO DATABASE
    $db = mysqli_connect("localhost", "root", "");
    mysqli_select_db($db, "magicsever");

    if(mysqli_connect_error()){

        die ("Database connection error");
    }
    //GET ALL THE SUBMITTED DATA
    $image = $_FILES['image']['tmp_name'];
    $name = $_FILES['image']['name'];

    //Store te submitted data to database
    $sql = "INSERT INTO image_test (name, image)VALUES ('$name','$image')";
    $query = mysqli_query($db, $sql);


    //Now lets move the uploaded image into the folder

    $nullResult = array();
    $nullResult['Image'] = (move_uploaded_file($_FILES['image']['tmp_name'], $target))? "Successful": "Unsuccessful";
    echo json_encode($nullResult);                      


    }
}

HTML:

<form action="index.php" method="post" enctype="multipart/form-data">

<input type="file" name="image">
    <br></br>
<input type="submit" name="submit" value="Upload">




</form>
  • 写回答

1条回答 默认 最新

  • doupao1530 2017-05-26 16:52
    关注

    $_POST['']; Parameters come from the usually the form that has the method set to POST, like yours has, that input type you have (file, named image) will be returned has $_POST['image'], $_REQUEST on the other hand is the "GET" method, it works in the same way, the only difference is it's not secure and it comes in the url. I would recommend using POST to be honest. Also use PDO because your code is vulnerable to SQL injection. (mentioned by Alex Howansky)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 逻辑谓词和消解原理的运用
  • ¥15 请求分析基于spring boot+vue的前后端分离的项目
  • ¥15 三菱伺服电机按启动按钮有使能但不动作
  • ¥15 js,页面2返回页面1时定位进入的设备
  • ¥200 关于#c++#的问题,请各位专家解答!网站的邀请码
  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?