Jump to content

upload image and insert image name in database


shahzad

Recommended Posts

i have around 200 images in a folder i want to upload it to the server and i want to store there name in mysql database.

i know the script to upload 1 at a time but i need to select the file every time

 

 

is it possible to give directory path and script will get all the images and get there name insert to the database??

 

 

thanks for your time and help in advance

If the files are local, then you shouldn't need to do any file transfers, but rather just provide the path name to the directory.

 

This is just an example, appropriate error handling is required.

 

<?php
// Open directory
$dir = opendir('path/to/directory');

// List files in images directory
while (($filename = readdir($dir)) !== false) {
  if ($filename != '.' || $filename != '..') {
    // You will need appropriate error handling
    $sql = mysql_query("INSERT INTO table_name ( filename ) VALUES ( '". $filename ."' )");
  }
}

closedir($dir);
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.