سلام وقتت بخیر...
باید برای اینکار نام تصویر را در دیتابیس هاست ذخیره کنید و از کد زیر استفاده کنید
if(isset($_POST['submit'])) {
//Process the image that is uploaded by the user
$target_dir = "uploads/";
$target_file = $target_dir . basename($_FILES["imageUpload"]["name"]);
$uploadOk = 1;
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
if (move_uploaded_file($_FILES["imageUpload"]["tmp_name"], $target_file)) {
echo "The file ". basename( $_FILES["imageUpload"]["name"]). " has been uploaded.";
} else {
echo "Sorry, there was an error uploading your file.";
}
$image=basename( $_FILES["imageUpload"]["name"],".jpg"); // used to store the filename in a variable
//storind the data in your database
$query= "INSERT INTO items VALUES ('$id','$title','$description','$price','$value','$contact','$image')";
mysql_query($query);
require('heading.php');
echo "Your add has been submited, you will be redirected to your account page in 3 seconds....";
header( "Refresh:3; url=account.php", true, 303);
}
برای بازیابی تصویر هم از این کد استفاده کنید
<?php
if(!empty($_GET['id'])){
//DB details
$dbHost = 'localhost';
$dbUsername = 'root';
$dbPassword = '*****';
$dbName = 'codexworld';
//Create connection and select DB
$db = new mysqli($dbHost, $dbUsername, $dbPassword, $dbName);
//Check connection
if($db->connect_error){
die("Connection failed: " . $db->connect_error);
}
//Get image data from database
$result = $db->query("SELECT image FROM images WHERE id = {$_GET['id']}");
if($result->num_rows > 0){
$imgData = $result->fetch_assoc();
//Render image
header("Content-type: image/jpg");
echo $imgData['image'];
}else{
echo 'Image not found...';
}
}
?>
موفق باشی...😉
آیا مایل به ارسال نوتیفیکیشن و اخبار از طرف راکت هستید ؟