I have uploads folder and inside there ,dynamically, I am creating another directory based on the image id.
I'm creating the directory but the image is not being saved in it! At the same time I want to store the path of the folder in the database.
if(isset($_POST['submit'])){
$img_id=$_POST['img_id'];
/* $imgpath= mkdir("uploads/".$img_id);
$path1= "$imgpath/".$_FILES['c_photo']['name'][0];
move_uploaded_file($_FILES['c_photo']['name'][0], $path1);
$img_photo=$_FILES['c_photo']['name'][0];
*/
// This code is saving the image in uploads folder instead off $imgpath directory
$imgpath=mkdir("uploads/".$img_id);
$path1="uploads/".$_FILES['c_photo']['name'][0];
move_uploaded_file($_FILES['c_photo']['tmp_name'][0],$path1);
$query1 ="INSERT INTO img_tbl(`img_id`,`img_photo`) VALUES ('$img_id', '$path1')";
if ($conn->query($query1) === TRUE) {
header("location:show_img.php?");
}
else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
$conn->close();
}
?>
<div class="col-sm-12">
<div class="col-sm-3">
<label>Image id</label>
</div>
<div class="col-sm-9">
<input class="form-control" type="text" name="img_id""/>
</div>
</div>
<div class="col-sm-12">
<div class="col-sm-3">
<label>Upload photo</label>
</div>
<div class="col-sm-9">
<input class="form-control" type="file" name="c_photo[]" />
</div>
</div>
<div class="col-sm-5">
<input class="form-control" type="submit" name="submit" value="Save"/>
</div>
Please help me. I am new in php. Thanks in Advance