จากโค้ดนี้ เวลาตอนที่เราไม่ได้เบราซ์ไฟล์ภาพ อยาก ให้มีค่า default part url ไปเก็บของ db แทน.... ต้องทำยังไงครับ
------------
// connect to database
include 'libs/db_connect.php';
// sql query
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(move_uploaded_file($temp_name, $target_path)) {
// if the form was submitted
if($_POST){
$sql = "INSERT INTO users (firstname, lastname, username, password,images_path,submission_date)
VALUES(?, ?, ?, ?,'".$target_path."','".date("Y-m-d")."')";
// if the statement was prepared
if($stmt = $mysqli->prepare($sql) ){
$stmt->bind_param(
"ssss",
$_POST['firstname'],
$_POST['lastname'],
$_POST['username'],
$_POST['password']
);
// execute the insert query
if($stmt->execute()){
echo "User was saved.";
$stmt->close();
}else{
die("Unable to save.");
}
}else{
die("Unable to prepare statement.");
}
// close the database
$mysqli->close();
}
}else{
exit("Error While uploading image on the server");
}
echo "<h1>Upload Complete </h1><br><img src='images/".$imagename."' width='300'> ";
}
ตอบ/อธิบาย