Django Anonymous
Django Anonymous

Reputation: 3025

unable to upload files

This is my script:-

if (isset($_POST['confirm_close_complaint_submit']))
{
    if($_FILES['complaint_file']['tmp_name'] == "none")
    {
        header('Location: complaint-register.php?FileSizeError=1');
        exit();
    }
    $filename = basename($_FILES['complaint_file']['name']);
    $ext = substr($filename, strrpos($filename, '.') + 1);
    if (($ext != "jpg") && ($_FILES["uploaded_file"]["type"] != "image/jpeg"))
    {
        header('Location: complaint-register.php?FileTypeError=1');
        exit();
    }
    else
    {
        $destination = '../../stored/complaint-files/'.$_POST['confirm_close_complaint'].$_FILES['complaint_file']['name'];
        $temp_file = $_FILES['complaint_file']['temp_name'];
        move_uploaded_file($temp_file, $destination);
        $insertSQL = sprintf("UPDATE complaints SET complaint_status='CLOSED', complaint_solved_date=NOW(), complaint_remark=%s WHERE complaint_number=%s",
                       GetSQLValueString($_POST['complaint_remark'], "text"),
                       GetSQLValueString($_POST['confirm_close_complaint'], "text"));
        $Result1 = mysql_query($insertSQL, $dacreint) or die(mysql_error());  
        header('Location: complaint-register.php?ComplaintClose=Successful');
        exit();
    }
}

This script do the mysql insertion but do not upload the file. It shows me successful message.

Here is my form:-

<form enctype="multipart/form-data" method="post" action="complaint-register.php">
    <table border="0">
    <tr>
    <td>Remark</td>
    <td><textarea name="complaint_remark" class="textarea"></textarea></td>
    </tr>
    <tr>
    <td>Complaint File</td>
    <td>
        <input type="hidden" name="MAX_FILE_SIZE" value="30000" />
        <input name="complaint_file" type="file" size="100" /></td>
    </tr>
    </table>
    <div class="clear"></div>
    <input name="confirm_close_complaint" type="hidden" value="'.$close_complaint.'" />
    <input name="confirm_close_complaint_submit" type="submit" class="Button" style="float:left;" value="Yes" />
    <input name="" type="button" class="Button" style="float:left;" onClick="javascript:history.go(-1)" value="No" />
    </form>

Is the way i am defining the path is correct i.e. $destination = '../../stored/complaint-files/'.$_POST['confirm_close_complaint'].$_FILES['complaint_file']['name'];??

And do this condition is ok $temp_file = $_FILES['complaint_file']['tmp_name'];

Upvotes: 0

Views: 87

Answers (2)

Sudhir Bastakoti
Sudhir Bastakoti

Reputation: 100195


$_FILES['complaint_file']['temp_name'];
should be

$_FILES['complaint_file']['tmp_name'];
Add your update statement inside if uploaded, like


if(move_uploaded_file($temp_file, $destination)) {
  //your update statement here
}
else {
  //error
}

Try to check if your destination path is valid. Set error reporting on:


ini_set('display_errors',1);
error_reporting(E_ALL);

Upvotes: 4

Emil Vikstr&#246;m
Emil Vikstr&#246;m

Reputation: 91983

Try handling errors from move_uploaded_file. You should not show a "success" message of that call fails.

Upvotes: 1

Related Questions