need help with images

I’m trying to add images to folder and keep path in DB and I have no idea how to added to this code. This code is working fine, but not adding images into DB as a blob.
please help

[php]if(isset($_POST[‘submit’])){

 $stmt = $connection->prepare("INSERT INTO advert (title, email, phone, place, options, name,  lastname,  message, kod ,  image, rodzaj, cena,  ip, user) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");

$stmt->bind_param(“sssssssssbssss”, $title, $email, $phone, $place, $options, $name, $lastname, $message, $randomString, $file, $rodzaj, $cena, $ip, $user);

        $file = addslashes(file_get_contents($_FILES["images"]["tmp_name"])); 
         
         
         $user=$_SESSION['login'];

$title=filter_var($_POST[‘title’], FILTER_SANITIZE_STRING);
$email=filter_var($_POST[‘email’], FILTER_SANITIZE_STRING);
$phone=filter_var($_POST[‘phone’], FILTER_SANITIZE_STRING);
$place=filter_var($_POST[‘place’], FILTER_SANITIZE_STRING);
$options=filter_var($_POST[‘options’], FILTER_SANITIZE_STRING);
$name=$_SESSION[‘login’];
$lastname=filter_var($_POST[‘lastname’], FILTER_SANITIZE_STRING);
$message=filter_var($_POST[‘message’], FILTER_SANITIZE_STRING);
$rodzaj=filter_var($_POST[‘optradio’], FILTER_SANITIZE_STRING);
$cena=filter_var($_POST[‘cena’], FILTER_SANITIZE_STRING);
$length = 10;

$randomString = substr(str_shuffle(“0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ”), 0, $length);
$_SESSION[‘codes’]=$randomString;
$ip=$_SERVER[“REMOTE_ADDR”];

$stmt->execute();[/php]

You need to move the image from the upload tmp dir to wherever you want to store it, you may want to generate a unique file name. You need to store that path (or only the file name) in the db, NOT the entire file.

I manage to add path to DB and images into folder , but now I need some help to display them in carousel

[php]$sql=“SELECT * FROM zdjecia WHERE user=’$user’ LIMIT 3”;
$final=mysqli_query($connection, $sql);
while($target=mysqli_fetch_array($final)){

        echo " <div class='container'>";

echo “

”;
echo "<ol class='carousel-indicators'>";
 echo " <li data-target='#myCarousel' data-slide-to='0' class='active'></li>";
 echo " <li data-target='#myCarousel' data-slide-to='1'></li>";
 echo " <li data-target='#myCarousel' data-slide-to='2'></li>";
echo "</ol>";

echo "

";
echo "
";
echo " Los Angeles";
echo "
";
 echo " <div class='item'>";
   echo " <img src='$target[2]' alt='Chicago' style='width:300px;'>";
 echo " </div>";

  echo "<div class='item'>";
   echo " <img src='$target[2]' alt='New york' style='width:300px;'>";
echo " </div>";
echo "</div>";

echo " “;
echo “”;
echo " Previous”;
echo “
”;
echo “”;
echo “”;
echo “Next”;
echo “
”;
echo “

”;
echo “
”;
         }
     }
    }

?>[/php] I get 3 sliders how can I display all 3 images in one?

You are doing the carousel in the loop, when you just want to echo out the image.

If you know the directory(folder) just contains images and you want to display just the images from that folder why don’t you just read the filenames into to an array? Instead of monkeying around with MySQL? (Reading in the paths)

For example this is what I do on my website:

[php]function list_files($path, $type) {
$directory = new \RecursiveDirectoryIterator($path);
$iterator = new \RecursiveIteratorIterator($directory);
$files = array();
foreach ($iterator as $info) {
if (in_array($info->getExtension(), $type)) {
$files[] = $info->getPathname();
}
}
return $files;
}

$path = ‘assets/uploads’; // start in this folder/directory
$type = array(‘png’, ‘jpg’); // find me this type of file…
$image_array = list_files($path, $type); // do it[/php]

I use Smarty (a templating engine), but can be easily done in plain old PHP ->
[php]


    {foreach $image_src as $src_path}
    {if $src_path@first}
  • Images

  • {else}
  • Images

  • {/if}
    {/foreach}
[/php]

You could even control what files are show by using RegEx and MySQl if you wanted too, but that’s considering you had a structured your filenames accordingly.

thank you guys I will have a look I hope it will work for me:-) I know that I’m doing loop I wasn’t sure how to display images into carousel or slide

Sponsor our Newsletter | Privacy Policy | Terms of Service