-1

我在将电子签名图像上传到用户个人资料时遇到问题,尽管我找不到出错的地方:( 我确实在需要指定的所有其他文件中包含了“签名”......我错过了什么吗?

<?php

if (isset($_GET['success']) === true && empty($_GET['success']) === true) {
    echo 'Your details have been updated!';
}
else {
    if (empty($_POST) === false && empty($errors) === true) {

        $update_data = array(
            'username' => $_POST['username'],
            'fullname' => $_POST['fullname'],
            'email' => $_POST['email'],
            'contact1' => $_POST['contact1'],
            'contact2' => $_POST['contact2'],
            'businessaddress' => $_POST['businessaddress'],
            'businessprovince' => $_POST['businessprovince'],
            'businesstown' => $_POST['businesstown'],
            'businesszip' => $_POST['businesszip'],
            'businessnumber' => $_POST['businessnumber'],
            'businessfax' => $_POST['businessfax'],
            'hrnumber' => $_POST['hrnumber'],
            'hremail' => $_POST['hremail'],
            'hrperson' => $_POST['hrperson'],
            'signature' => $_POST['signature'],
            'allow_email' => ($_POST['allow_email'] == 'on') ? 1 : 0
        );

        update_user($session_user_id, $update_data);
        header('Location: settings.php?success');
        exit();
    }
    else if (empty($errors) === false) {
        echo output_errors($errors);
    }

    function update_user($user_id, $update_data)
    {
        $update = array();
        array_walk($update_data, 'array_sanitize');

        foreach ($update_data as $field => $data) {
            $update[] = '`' . $field . '` = \'' . $data . '\'';
        }

        mysql_query("UPDATE `users` SET " . implode(', ', $update) . " WHERE `user_id` = $user_id");
    }

}
?>

<form action="" method="post" enctype="multipart/form-data">
        <table cellpadding="5" cellspacing="5" width="600px">
            <tr>
                <td></td>
                <td></td>
            </tr>
        </table>
        <table cellpadding="5" cellspacing="5" width="600px">
            <tr>
                <td valign="top">
                    <table cellpadding="5" cellspacing="5" width="100%">
                        <tr>
                            <td>UserName*:</p></td>
                            <td><input type="text" name="username" value="<?php echo $user_data['username']; ?>" /></td>
                        </tr>
                        <tr>
                            <td>Full Name*:</td>
                            <td><input type="text" name="fullname" value="<?php echo $user_data['fullname']; ?>" /></td>
                        </tr>
                        <tr>
                            <td>Emial Address*:</td>
                            <td><input type="text" name="email" value="<?php echo $user_data['email']; ?>" /></td>
                        </tr>
                        <tr>
                            <td>Contact Number 1*:</td>
                            <td><input type="text" name="contact1" value="<?php echo $user_data['contact1']; ?>" /></td>
                        </tr>
                        <tr>
                            <td>Work Number:</td>
                            <td><input type="text" name="contact2" value="<?php echo $user_data['contact2']; ?>" /></td>
                        </tr>
                        <tr>
                            <td>
                                <input type="checkbox" name="allow_email" <?php if ($user_data['allow_email'] == 1) { echo 'checked="checked"'; } ?>> Would you like to receive email from us?</td>
                        </tr>
                        <tr>
                            <td>Your Electronic Signature</td>
                            <td><input type="file" name="signature" value="signature"></td>
                        </tr>
                    </table>
                </td>
                <td>
                    <table cellpadding="5" cellspacing="5" width="100%">

                        <tr>
                            <td>Business Address*:</td>
                            <td><input type="text" name="businessaddress" value="<?php echo $user_data['businessaddress']; ?>" /></td>
                        </tr>
                        <tr>
                            <td>Business Province*:</td>
                            <td><input type="text" name="businessprovince" value="<?php echo $user_data['businessprovince']; ?>" /></td>
                        </tr>
                        <tr>
                            <td>Business Town*:</td>
                            <td><input type="text" name="businesstown" value="<?php echo $user_data['businesstown']; ?>" /></td>
                        </tr>
                        <tr>
                            <td>Business Address Zip*:</td>
                            <td><input type="text" name="businesszip" value="<?php echo $user_data['businesszip']; ?>" /></td>
                        </tr>
                        <tr>
                            <td>Office Tel Number*:</td>
                            <td><input type="text" name="businessnumber" value="<?php echo $user_data['businessnumber']; ?>" /></td>
                        </tr>
                        <tr>
                            <td valign="top">Office Fax Number:</td>
                            <td valign="top"><input type="text" name="businessfax" value="<?php echo $user_data['businessfax']; ?>" /></td>
                        </tr>
                    </table>
                </td>
            </tr>
        </table>
        <h3>Human Resources Department Details</h3>
        <table cellpadding="5" cellspacing="5" width="600px">
            <tr>
                <td>HR Contact Number:<br /><input type="text" name="hrnumber" value="<?php echo $user_data['hrnumber']; ?>" /></td>
                <td>HR Email Address:<br /><input type="text" name="hremail" value="<?php echo $user_data['hremail']; ?>" /></td>
                <td>HR Contact person:<br /><input type="text" name="hrperson" value="<?php echo $user_data['hrperson']; ?>" /></td>
            </tr>
            <tr>
                <td></td>
                <td></td>
                <td><input type="submit" value="Update all"></td>
            </tr>
        </table>        
    </form>
4

1 回答 1

3

您有一个“签名” html 文件字段,并且您正在从 $_POST 读取它,就像它是一个字符串(不是)一样。

PHP 中上传的文件将使用有用的数据填充 $_FILES 以检索文件。

在您的情况下, $_FILES['signature']['tmp_name'] 将是一个字符串,表示文件临时存储的位置。

如果要将文件保存在某处,则必须执行以下操作:

$tmp_name = $_FILES['signature']['tmp_name'];
$path = "/some/path/".$_FILES['signature']['name'];
move_uploaded_file($tmp_name, $path);

而不仅仅是阅读 $_POST['signature'] (顺便说一句,不会设置)。

于 2013-09-25T13:40:55.987 回答