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

Link to comment
Share on other sites

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);
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.