无法上传我的文件

时间:2012-06-20 12:19:21

标签: php mysqli

我有这个表格我试图上传我的图像,但每次我“更新”页面返回正常,没有任何内容上传到我的文件夹“ProfilesImages”我的错。

<?php
if(isset($_POST['update'])){
    $ProfileImage = $_FILES['ProfileImage']['name'];
    $Fname = clean_text($_POST['Fname']);
    $Lname = clean_text($_POST['Lname']);
    $Uemail = $_POST['Remail'];
    $Uwebsite = $_POST['website'];
    $Ugender = clean_text($_POST['select']);
    $Ubirth = (int)$_POST['birth'];
    $UWork = clean_text($_POST['company']);
    $Uabout = clean_text($_POST['aboutMe']);
    $Uhobby = clean_text($_POST['hobby']);
    $Uprivatie = $_POST['radio'];
    $target = "includes/ProfilesImages/";
    $target = $target . basename ($_FILES['ProfileImage']['name']);
    $updateUserData = "UPDATE loginaccess SET
        profile_image='".$ProfileImage."',
        FUname = '".$Fname."',
        LUname = '".$Lname."',
        Email = '".$Uemail."',
        Website = '".$Uwebsite."',
        gender = '".$Ugender."',
        birth = '".$Ubirth."',
        work = '".$UWork."',
        about = '".$Uabout."',
        hobby = '".$Uhobby."',
        privatie = '".$Uprivatie."' where Email='".$_SESSION['email']."' AND active=1";
    if(move_uploaded_file($_FILES['ProfileImage']['tmp_name'], $target))
    {
            echo "<p>The image you have attached was uploaded successfully</p>";
    }
    else
    {
            echo " <p><strong>Notes</strong> : no image was attached to the registration form..! </p>";
    }
    $updateUserDataResults= $db->query($updateUserData) or die("$db->error");
    if($updateUserDataResults){
            header("Location:index.php?cat=user&learn_id=1");
    }
}
?>

任何帮助PLZ ......

2 个答案:

答案 0 :(得分:4)

请务必在表单中设置fileupload enctype

<form action="index.php" method="post" enctype="multipart/form-data">

否则文件将不会上传

答案 1 :(得分:0)

我认为你在这里做的是将图像名称上传到sql中,根据我对此代码的理解,你根本没有将图像文件上传到文件夹。尝试使用此代码将图像文件上传到所需的文件夹,在本例中为上传文件夹:

//if a replacement file is selected
//delete old file from filesystem
$sql2 = "Select item_image From Items Where item_id = '".$_POST['item_id']."'";
$stmt2 = $dbh->prepare($sql2);
    $stmt2->execute();
$result = $stmt2->fetchAll();
$file = strval($result[0]["item_image"]);
unlink($file);

//Uploads new picture file to filesystem
if ((($_FILES["file"]["type"] == "image/gif")
    || ($_FILES["file"]["type"] == "image/jpeg")
    || ($_FILES["file"]["type"] == "image/pjpeg")
    || ($_FILES["file"]["type"] == "image/jpg")
    || ($_FILES["file"]["type"] == "image/png"))
    && ($_FILES["file"]["size"] < 20000000)){
if ($_FILES["file"]["error"] > 0){
    echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
                                  }//if
else{
    if (file_exists("upload/" . $_FILES["file"]["name"])){
         echo "<strong>That file is already on our database. Please choose a different file     or rename the file that was just rejected and resubmit your order.</strong>";}//if
    else{
        move_uploaded_file($_FILES["file"]["tmp_name"], "upload/" . $_FILES["file"]  ["name"]);
        echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
    echo "uploaded new picture to filesystem" . "<br />";

它不是特定于您的名字和文件,但检查它,它应该工作。您应该使用它来删除更新的旧文件。

相关问题