PHP文件上传:语法


PHP File Upload: Syntax?

我目前正在创建一个系统,用户可以将这两种信息和相应的图片上传到数据库。但是,当我调用move_upload_file()函数时,它不喜欢指定新目标时的语法。

我所指的代码行如下:

if(move_uploaded_file($_FILES['upload']['tmp_name'], "images/{$_FILES['upload']['name']")){

我得到的错误是

分析错误:语法错误,意外的"){'(T_CONSTANT_ENCAPSED_STRING),中应为"}"/Applications/XAMPP/examplefiles/htdocs/serverside/phptut/addbyform.php在线27

我还使用了Sublime Text 2和[上传]亮粉色突出显示。

对于进一步的上下文,这是我迄今为止的整个脚本:

<?php
printForm();
//when "submit" tie together values and variables
if($_POST['submit']=="Submit"){
    $email = cleanData($_POST['email']);
    $first = cleanData($_POST['first']);
    $last = cleanData($_POST['last']);
    $status = cleanData($_POST['status']);
    //$image = cleanData($_POST['image']);
    //echo "Data cleaned";
    addData($email, $first, $last, $status);
}
else{
    //printForm();
}

function checkUpload(){
    //check for uploaded files
    if(isset($_FILES['upload'])){ //upload refers to form element "upload"
        $allowed = array ('image/pjpeg', 'image/jpeg', 'image/JPG', 'image/X-PNG', 'image/PNG', 'image/png', 'image/GIF');
        if(in_array($_FILES['upload']['type'], $allowed)){//if upload if in the allowed file types
            echo "uploading files...";
            //move the file over
            if(move_uploaded_file($_FILES['upload']['tmp_name'], "images/{$_FILES['upload']['name']")){
                //moveuf method moves to tmp folder then moves to final location
                echo "<p>The file has been uploaded 'dude'</p>";
                $image="{$_FILES['upload']['name']}";
                print "$image";
            }//end of moving DAT IMG :3
            else{
                echo '<p>Please upload a  JPEG, GIF or PNG image.<p>';

                if($FILES['upload']['error'] > 0){
                }
            }
        }
    }
}


//cleans information
function cleanData($data){
    if(!$status){ //everything except for status take out spaces
        $data = trim($data);
    }
    $data = stripslashes($data);//no slashes
    $data = htmlspecialchars($data);//no special characters
    $data = strip_tags($data);//no html tags
    return $data;
}
//inserts data into db
function addData($email, $first, $last, $status){
    //echo "Ready to add data";
    include("dbinfo.php");//access db
    $image = checkUpload();
    $sql = "INSERT INTO contacts VALUES(null, '$email', '$first', '$last', '$status', '$image')";
    //null because of ID aka primary key automatically incremented:3
    $result = mysql_query($sql) or die(mysql_error());
    //takes sql arugment for query OR if it can't you get a BUMMER DUDE
    echo <<<HERE
    <b>The following has been added:</b>
    <ul>
    <li>E-mail: $email</li>
    <li>First: $first</li>
    <li>Last: $last</li>
    <li>Status: $status</li>
    <li>Image File:<br/> <img src="images/$image" /></li>
    </ul>
HERE;
}
function printForm(){
    $pageTitle ="Add a Contact";
    include("header.php");
    echo <<<EOD
        <b>Add a Contact</b>
        <form method = "POST" enctype="multipart/form-data">
        <div>
            <label for="email">Email*:</label>
            <input type="text" name="email" id="email" required="required">
        </div>
        <div>
            <label for="first">First Name*:</label>
            <input type="text" name="first" id="first" required="required">
        </div>
        <div>
            <label for="last">Last Name*:</label>
            <input type="text" name="last" id="last" required="required">
        </div>
        <div>
            <label for="status">Status*:</label>
            <input type="text" name="status" id="status" required="required">
        </div>
        <div>
            <label for="image">Image*:</label>
            <input type="file" name="upload" size="30" id="upload" required="required"><br/>
            <small>Must be less than 512kb. Only JPG, GIF, and PNG files</small>
        </div>
        <div id="mySubmit">
            <input type="submit" name="submit" value="Submit">
        </div>
        </form>
EOD;
}
include("footer.php");
?>

有人能告诉我我做错了什么吗?谢谢

您错过了一个括号!

if(move_uploaded_file($_FILES['upload']['tmp_name'], "images/{$_FILES['upload']['name']}")){

[名字]后面的那个。。。