PHP图像上传不起作用

时间:2013-04-14 16:46:54

标签: php mysql image

我正在尝试创建一个表单,用户可以在其中上传带有标题和说明的图像。除了没有移动到我的服务器的图像之外,一切正常。谁能告诉我这里我做错了什么?我正在尝试上传到的文件夹的权限设置为777。

PHP代码:

<?php 
}

session_start();
if(!session_is_registered(myusername))
{
    header("location:login.php");
}

// connect to the database
$conn=mysql_connect(*censored*) or die("Kan geen verbinding maken met de DB server"); 
mysql_select_db("frankkluytmans_",$conn) or die("Kan database niet selecteren"); 

// check if the form has been submitted. If it has, start to process the form and save    it to the database
if (isset($_POST['submit']))
{ 
    // get form data, making sure it is valid
    $pagid = mysql_real_escape_string(htmlspecialchars($_POST['pagid']));
    $titlename = mysql_real_escape_string(htmlspecialchars($_POST['title']));
    $contentname = mysql_real_escape_string(htmlspecialchars($_POST['contentedit']));
    $image = mysql_real_escape_string(htmlspecialchars("/gfx/".$_FILES["image"]["name"])); 

    // check to make sure both fields are entered
    if ($titlename == '' || $pagid == '')
    {
        // generate error message
        $error = 'ERROR: Please fill in all required fields!';

       // if either field is blank, display the form again
       renderForm($pagid, $titlename, $contentname, $error);
    }
    else
    {
        if (move_uploaded_file($_FILES["image"]["tmp_name"],     "/gfx/".$_FILES["image"]    ["name"])) 
        {
            // save the data to the database
            mysql_query("INSERT frankkluytmans SET pagid='$pagid', title='$titlename',       content='$contentname', image='$image'") or die(mysql_error()); 

             // once saved, redirect back to the view page
             header("Location: index.php"); 
         }
    }
}
else
// if the form hasn't been submitted, display the form
{
    renderForm('','','');
}
?> 

表格:

<form action="" method="post" enctype="multipart/form-data">
         <h2>
             <span>NEW</span>
             <input type="text" name="pagid" value="" />
         </h2>
         <div class="pages-content">
         <strong>Title: *</strong> <input type="text" name="title" /><br/>
         <strong>Content: *</strong> <textarea name="contentedit"</textarea><br/>
         <input type="file" name="image" id="image" />
         <input type="submit" name="submit" value="Submit">
         </div>
         <script>
            window.onload = function() {
                CKEDITOR.replace( 'contentedit' );
                console.log("editor werkt");
            };
         </script>
</form> 

3 个答案:

答案 0 :(得分:0)

您的PHP代码已损坏:

<?php 
}

答案 1 :(得分:0)

您的文件中存在错误,它以}

开头

答案 2 :(得分:0)

  1. 您在第一行有不受欢迎的}

  2. 您确定位置是否正确?

  3. 尝试在目录前添加$_SERVER['DOCUMENT_ROOT'],例如:

    $image_dir = $_SERVER['DOCUMENT_ROOT']."/gfx/".$_FILES["image"]["name"];