1

I have checked php.ini File upload is On. Below is the code Please Help me. File is not uploading into the folder images. I don't know what is the Problem with the code. The problem is not in query , because (!empty($_FILES["uploadedimage"]["name"])) not uploads the image.

<form enctype="multipart/form-data" method="post">
                                     <th><input style=" width:100px; font-size:13px" name="op"  Placeholder="Operator Name"/></th>
 <th>  <input class="file-upload-input" type="file" name="uploadedimage"></th>

<th> <input class="btn btn-danger" type="submit" name="uploadnow" value="SUBMIT" class="theme-btn btn-style-one"></th>


                                    </tr></form>
                                <?php

    function GetImageExtension($imagetype)
     {
       if(empty($imagetype)) return false;
       switch($imagetype)
       {
           case 'image/bmp': return '.bmp';
           case 'image/gif': return '.gif';
           case 'image/jpeg': return '.jpg';
           case 'image/png': return '.png';

           default: return false;
       }
     }

if (!empty($_FILES["uploadedimage"]["name"])) {

    $file_name=$_FILES["uploadedimage"]["name"];
    $temp_name=$_FILES["uploadedimage"]["tmp_name"];
    $imgtype=$_FILES["uploadedimage"]["type"];
    $ext= GetImageExtension($imgtype);
    $imagename=date("d-m-Y")."-".time().$ext;
    $target_path = "images/".$imagename;    
if($_POST['uploadnow'])
{
$op=$_POST['op'];
if(move_uploaded_file($temp_name, $target_path)) {
    $sql="INSERT INTO operator(op,mono) VALUES('".$op."','".$target_path."') ";
    mysql_query($sql) or die
    ("error in $query_upload == ----> ".mysql_error());  
    }
}

?> <script type="text/javascript">
document.location.href='operator.php';
</script>
<?php

}
?>
2
  • Is the data being saved in db Commented Jun 28, 2017 at 8:43
  • your code seems correct..check the folder permission. Commented Jun 28, 2017 at 8:49

2 Answers 2

1

Try with $target_path = "/images/".$imagename;

Sign up to request clarification or add additional context in comments.

2 Comments

I check but not working , can you please recheck the code
The code looks legit, try to debug. Try echo "join" in that if (!empty($_FILES["uploadedimage"]["name"])) {
0

Try putting these lines at the top of your code to show all PHP errors/warnings and see what you get.

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.