PHP file is not uploading -
i have form in can upload image. reason not able upload image. have updated file permissions (777 permissions) , still file not upload. form seems working because text (not included in form updating)
<form action="manage_content.php?project=5" method="post" enctype="multipart/form-data"> <div class="width"> <p>project image: <br> <input type="file" name="image_file" id="file" class="inputfile" /> <label for="file">choose file</label> </p> </div> <input type="submit" name="update_project" value="update current project"> </form>
the php form processing.
if (isset($_post['update_project'])) { $required_fields = array("project_name", "date", "content"); validate_presences($required_fields); $fields_with_max_length = array("project_name" => 30); validate_max_length($fields_with_max_length); $id = $current_project["id"]; $project_name = mysql_prep($_post["project_name"]); $date = mysql_prep($_post["date"]); $content = mysql_prep($_post["content"]); $target_dir = "images/"; $target_file = $target_dir . basename($_files["image_file"]["name"]); $uploadok = 1; $imagefiletype = pathinfo($target_file,pathinfo_extension); print_r($_files); echo "<br>" . $target_file; if (empty($errors)) { if($_files["image_file"]["error"] == 4) { //means there no file uploaded $query = ""; $result = mysqli_query($connection, $query); if ($result && mysqli_affected_rows($connection) >= 0) { $_session["message"] = "subject updated"; // redirect_to("manage_content.php?subject=$current_subject[id]"); } } else { $query = ""; $result = mysqli_query($connection, $query); if ($result && mysqli_affected_rows($connection) >= 0) { $_session["message"] = "subject updated"; // redirect_to("manage_content.php?subject=$current_subject[id]"); } } } else { $message = "subject creation failed."; } } else { // request // end of post submit } ?>
print_r($_files) gives me:
array ( [image_file] => array ( [name] => 1.jpg [type] => image/jpeg [tmp_name] => c:\xampp\tmp\phpf5aa.tmp [error] => 0 [size] => 24397 ) ) , echo $target_file gives: images/1.jpg
be sure directory uploading has same permissions , ownership program uploading file. should have write permissions user. same go file if exists, must have write permissions in order replace file.
wiki
Comments
Post a Comment