图像未保存到PHP中的文件夹

图像未保存到PHP中的文件夹,php,Php,我正在尝试将图片上载到我的服务器,并将图片名称保存到我的数据库中。但如果我填写表格,它只会刷新,什么也不做。有人知道它为什么不保存到文件夹吗 如果单击“提交”按钮,我将运行以下PHP代码: <?php if(isset($_POST['btn_save_updates'])) { $id = $_GET['id']; $email = $_POST['email']; $signature = $_POST['signature']; //if they DID upload a fi

我正在尝试将图片上载到我的服务器,并将图片名称保存到我的数据库中。但如果我填写表格,它只会刷新,什么也不做。有人知道它为什么不保存到文件夹吗

如果单击“提交”按钮,我将运行以下PHP代码:

<?php
if(isset($_POST['btn_save_updates'])) {

$id = $_GET['id'];
$email = $_POST['email'];
$signature = $_POST['signature'];

//if they DID upload a file...
if($_FILES['avatar']['name'])
{
//if no errors...
if(!$_FILES['avatar']['error'])
{
//now is the time to modify the future file name and validate the file
$new_file_name = strtolower($_FILES['avatar']['tmp_name']); //rename file
if($_FILES['avatar']['size'] > (2048000)) //can't be larger than 1 MB
{
$valid_file = false;
$error = 'Oops!  Your file\'s size is to large.';
}

//if the file has passed the test
if($valid_file)
{
//move it to where we want it to be
move_uploaded_file($_FILES['avatar']['tmp_name'], 'avatar/'.$new_file_name);
$filename = $_FILES['avatar']['name'];
// run update statement here ...
$error = 'Settings have been updated.';
}
}
//if there is an error...
else
{
//set that to be the returned message
$error = 'Oops!  Error:  '.$_FILES['avatar']['error'];
}
} 
}
?>

您忘记将
enctype=“多部分/表单数据”
添加到表单中

<form method="post" role="form" autocomplete="off">
    <div class="form-group">
        <label for="email">Email</label>
        <input type="text" name="email" id="email" tabindex="1" class="form-control" value="<?php userProfile("email"); ?>" autocomplete="off">
    </div>

    <div class="form-group">
        <label for="signature">Signature <i id="sign_tooltip" class="fa fa-exclamation-circle" aria-hidden="true" ata-toggle="tooltip" data-placement="right" title="You can add images to your signature!"></i></label>
        <script>
        $("#sign_tooltip").hover(function(){
            $('#sign_tooltip').tooltip('show')
        });
        </script>
        <textarea rows="4" name="signature" id="signature" tabindex="3" class="form-control" autocomplete="off"><?php userProfile("signature"); ?></textarea>
    </div>
    <br /><br />
    <div class="form-group">
        <label for="email">Avatar</label><br /><br />
        <img src="avatars/<?php userInfo('avatar'); ?>" alt="Default Avatar" class="img-circle" width="140" height="140"><br /><br />
        <input name="avatar" id="avatar" tabindex="4" class="input-group" type="file" accept="image/*" />
    </div>

    <div class="form-group">
        <div class="row">
            <div class="col-xs-7">
            </div>
            <div class="col-xs-5 pull-right">
                <button type="submit" name="btn_save_updates" id="btn_save_updates" tabindex="5" class="form-control btn btn-success"><i class="fa fa-floppy-o" aria-hidden="true"></i> Save </button>
            </div>
        </div>
    </div>
</form>