php image uploader无法正常工作

时间:2013-12-19 00:59:46

标签: php mysql image-uploading

我正在尝试使用此代码将图像添加到我的服务器和数据库中,但我无法弄清楚我做错了什么。

名称和链接字段被正确添加到数据库中,但图像名称没有,也没有文件上传到服务器。

addslide.php代码

 <?php
include('connect.php');

?>

<?php include("adminheader.php"); ?>
<div class="yellowbanner"></div>
    <div class="container">
        <div class="page">
            <h1>Add Slide</h1>
            <p>Add the details of the new slide below:</p>

            <form enctype="multipart/form-data" method="post" action="updateaddslide.php">
                <label>Slide Name:</label>
                <input type="text" name="name" placeholder="Slide Name" required />

                <label>Slide Link:</label>
                <input type="text" name="link" placeholder="Slide Link" />

                <label>Slide Image (Optimal size is 960x300 pixels):</label>
                <input type="file" name="image" required />

                <input type="submit" value="Add Slide" class="redbutton" />
            </form>
        </div>

    </div>

<?php include("../footer.php"); ?>

和updateaddslide.php代码

    <?php
include('connect.php');

$newslidename=$_POST['name'];
$newslidelink=$_POST['link'];

$sentfilename = $_FILES['image']['name'];
$sentfiletemp = $_FILES['image']['tmp_name'];

if(!empty($sentfilename)){
    move_uploaded_file($sentfiletemp,"uploaded/$sentfilename");
    }else{
    echo "<p>no file selected";
    die();
}

$newslidequery = "INSERT INTO slides(id, slidename, slidelink, slideimage) VALUES(NULL,'$newslidename', '$newslidelink', '$sentfilename')";

$newslidedidisplay = mysql_query($newslidequery) or die(mysql_error()); 

$query = "SELECT * FROM slides;";
$display = mysql_query($query) or die(mysql_error());   
?>

0 个答案:

没有答案