0

我有这个表格,我正在尝试上传我的图片,但每次我“更新”页面返回正常并且没有任何内容上传到我的文件夹“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");
    }
}
?>

任何帮助请...

4

2 回答 2

4

请务必在您的表单中设置 fileupload enctype

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

否则文件将不会上传

于 2012-06-20T12:23:57.190 回答
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 />";

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

于 2012-06-20T12:36:18.057 回答