Jump to content

Updating mysql database with a lot of file

- - - - -

  • Please log in to reply
3 replies to this topic

#1
amir2000

amir2000

    Newbie

  • Members
  • PipPip
  • 13 posts
Hi All,

Is there any way to update / insert a lot of files (photos) to mysql database?
I have a lot of photos on my website and I want to enter all into database.


Thanks,

Amir

#2
DarkLordofthePenguins

DarkLordofthePenguins

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 409 posts
What exactly is it that you're trying to do? Are you asking how to automate the process of inserting records?
Programming is a journey, not a destination.

#3
Alexander

Alexander

    It's Science!

  • Moderators
  • 4,118 posts
  • Location:Vancouver, Eh! Cleverness: 200
You can use glob() to fetch an array of image names and then join()/implode() them into the database query.

A simplistic example. This assumes you had set up a simple table with autoincrement and the table is named "photos":
$photoarray = array();
foreach (glob('/photos/*.jpg') as $filename) {
    $photoarray[] = "'$filename'";
}

$sql = "INSERT INTO photos VALUES (" . join(',', $photoarray) . ")";
$result = mysql_query($sql);

Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.

#4
amir2000

amir2000

    Newbie

  • Members
  • PipPip
  • 13 posts
sorry but is it possible to explain a bit more about your suggestion?




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users