在页面之间传递变量然后图像上传

时间:2014-12-08 22:07:01

标签: php mysql image variables

我需要将一些图像上传到我的MySQL数据库。最终我想要实现的是一个网站,为我们的客户存储地址,电话号码等数据。我现在想要做的是将图像与每个网站相关联。

我的数据库中有两个表:

表1:“网站详细信息”

  1. 第1栏:'site_id'
  2. 第2栏:'地址'
  3. 第3栏:'image'
  4. 表2:'拓扑'

    1. 第1栏:'image_id'
    2. 第2栏:'名字'
    3. 第3栏:'image'
    4. 第4栏:'site_id'
    5. 我的想法是,当有人点击某个网站时,该网址会包含该变量,如下所示:

      http://localhost:8888/testsite/site/14
      

      在该网站中,他们可以点击名为“上传图片”的链接。当他们点击该图像时,网站ID将被传递到下一页($ site_id已通过页面上方的mysql查询捕获):

      <a href="../topology?site_id=<?php echo $site_id;?>">Upload Topology</a>
      

      在下一页“拓扑”中,我有一个表单:

        <form enctype="multipart/form-data" action="process-upload-topology" method="post">
        <input name="image" type="file"> <input type="submit" value="Submit" />
        </form>
      

      然后处理上传的页面“

      <?php
      include("core/connect.php");
      
          //file properties
          $file = $_FILES['image']['tmp_name'];
      
          if (!isset($file)){
            echo "<p>Please Select an Image</p>";
          } else {
            $image = mysqli_real_escape_string($con, file_get_contents($_FILES['image']['tmp_name']));
            $image_name = mysqli_real_escape_string($con, $_FILES['image']['name']);
            $image_size = getimagesize($_FILES['image']['tmp_name']);
      
            if ($image_size==FALSE) {
              echo "<p>Invalid image type</p>";
      
            } else {
      
            if(!$insert = mysqli_query($con, "INSERT INTO topology (image_id, name, image) VALUES ('','$image_name','$image')")){
                echo ("<p>Error Uploading Image: " . mysql_error() . "</p>");
              } else {
                $lastid = mysqli_insert_id();
                echo "<p>Your image has been uploaded successfully!</p>";
      
              }
            }
          }
      ?>
      

      我的目标最终是每张照片都与该网站相关联。

0 个答案:

没有答案