PHP + HTML , Wampserver
This will show how to
send file name to database and store file in a folder
<?php $db_con=mysqli_connect('localhost','root','','photos') or die("Connection error"); if(isset($_FILES['photoUp']['name'])){ $phname=$_FILES['photoUp']['name']; $phtmp=$_FILES['photoUp']['tmp_name']; $pherror=$_FILES['photoUp']['error']; $phExt=end(explode(".",$phname)); $phSaveName=rand(10000,99999).".".$phExt; if($pherror==1){ echo"file error"; exit(); } $movePhoto=move_uploaded_file($phtmp, "Photos/$phSaveName"); if($movePhoto!=true){ echo"file move error"; exit(); } $sql = "INSERT INTO photo(photoname) VALUES ('$phSaveName')"; $query = mysqli_query($db_con, $sql); mysqli_close($db_con); header('location:index.php'); exit(); }else{ echo "Error"; } ?>
No comments:
Post a Comment