doumiang2297 2014-10-08 10:06
浏览 53
已采纳

放入数据库的图像信息(名称,类型,大小,URL)

I'm trying to insert image information to a database, the url, name, type and size. I made my database like with thees names,

Idimage name size type url

The code that I have made will upload the image to a folder after that I was trying to get the information in the database, but it doesn't work.

The Codes:

<?php
    if(isset($_POST['upload']))
    {
        $dbhost = 'localhost';
        $dbuser = 'root';
        $dbpass = 'root';
        $conn = mysql_connect($dbhost, $dbuser, $dbpass);
        if(! $conn )
        {
          die('Could not connect: ' . mysql_error());
        }

        $name = $_FILES['file']['name'];
        $type = $_FILES['file']['type'];
        $size = $_FILES['file']['size'];

        $sql =  "INSERT INTO". 
                " `image`(`name`, `url`, `size`, `type`) VALUES " . 
                " (`$name`,". 
                "`images/contentImages/"."`$name`"."`$type`""".
                ",$size".
                ",`$type`)";

        mysql_select_db('vgv');
        $retval = mysql_query( $sql, $conn );
        if(! $retval )
        {
          die('Could not update data: ' . mysql_error());
        }
        echo "Updated data successfully
";
        mysql_close($conn);
    }
?>




<?php include ('includes/header.php') ?>
    <?php 
        use foundationphp\UploadFile;

        $max = 1024 * 1024;
        $result = array();
        if (isset($_POST['upload'])) {
            require_once 'src/foundationphp/UploadFile.php';
            $destination = __DIR__ . '/images/contentImages/';
            try {
                $upload = new UploadFile($destination);
                $upload->setMaxSize($max);
                $upload->allowAllTypes();
                $upload->upload();
                $result = $upload->getMessages();
            } catch (Exception $e) {
                $result[] = $e->getMessage();
            }   
        }
    ?>
    <?php include ('includes/update_image.php'); ?>
    <div id=box>
        <div id="box-header">

        </div>
        <div id="box-container">
            <div id="box-content">

            </div>
            <div id="box-footer"></div>
        </div>
    </div>
    <div id="image-info">
        <div id="image">

        </div>
        <div>
            <table>
                <tr>
                    <td class="benaming">Naam</td>
                    <td class="naam"></td>
                </tr>
                <tr>
                    <td class="benaming">Type</td>
                    <td class="naam"></td>
                </tr>
                <tr>
                    <td class="benaming">Afmeting</td>
                    <td class="naam"></td>
                </tr>
                <tr>
                    <td class="benaming">Grote(MB)</td>
                    <td class="naam"></td>
                </tr>
                <tr>
                    <td class="benaming">URL</td>
                    <td class="naam"></td>
                </tr>
            </table>
        </div>
        <div id="knoppen">
            <form action="" method="post" enctype="multipart/form-data">
                <input type="file" name="filename[]" id="filename" multiple>
                <input type="submit" name="upload" id="submit" value="Upload File">
            </form>
            <?php 
                if ($result) { 
                    foreach ($result as $message) {
                        echo '<script>alert($message);<script>';
                    }
                } 
            ?>
        </div>
    </div>

<?php include ('includes/footer.php') ?>

The problem was that it was not $_POST['sumbit'] but $_POST['upload']

  • 写回答

1条回答 默认 最新

  • douan2907 2014-10-08 10:13
    关注
    $url =  "`images/contentImages/". $name . "." . $type . "";
    $sql =  "INSERT INTO". 
                " `image`(`name`, `url`, `size`, `type`) VALUES " . 
                " (`$name`". 
                ", `$url`".
                ", `$size`".
                ",`$type`)";
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 用visual studi code完成html页面
  • ¥15 聚类分析或者python进行数据分析
  • ¥15 逻辑谓词和消解原理的运用
  • ¥15 三菱伺服电机按启动按钮有使能但不动作
  • ¥15 js,页面2返回页面1时定位进入的设备
  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?