Jump to content

Saving images into database!


katerina

Recommended Posts

Hi,

I would like to insert the code of a website into a database.

However, I don't know how I can insert it.

So I thougth that is better to save into a table all the images, in another table all lists etc.

 

My code for saving images is :

 

 

<?php

if (!@mysql_connect('localhost', 'root', ''))
{
    echo " ".mysql_error();
    exit;
}
elseif (!@mysql_select_db('Diplwmatikh'))
{
    echo " ".mysql_error();
    exit;
}

$url="http://www.e-gov.gr";
$file = file_get_contents($url);

preg_match_all ('#(?:<img )([^>]*?)(?:/?>)#is', $file, $imgtags, PREG_PATTERN_ORDER );

$imgcontents = array();

foreach ( (array) $imgtags[1] as $img )
{

    preg_match_all ( '#([a-zA-Z]*?)=[\'"]([^"\']*)["\']#i', $img, $attributes, PREG_PATTERN_ORDER );
    $attrs = array();
    foreach ( (array) $attributes[1] as $key => $attr )
    {
        $attrs[$attributes[1][$key]] = $attributes[2][$key];
    }
    $imgcontents[] = $attrs;
}


foreach($imgcontents as $img => $key1) {

    $id = $img;
   
   
    $query = "INSERT INTO eikones (id) VALUES ('" .$id. "')";
    mysql_query($query);

    foreach($key1 as $imgs => $key2) {
   
        if ($imgs == 'src') {
       
            $img = array_reverse(split('/', $key2));
           
            $key2 = $img[0];
        }
     
       
        $query = "UPDATE eikones SET " .$imgs. " = '" .$key2. "' WHERE id = '" .$id. "'";
        mysql_query($query);
   
    }
}

mysql_close(); 

?>

 

and my mysql code is :

 

CREATE TABLE eikones(
id smallint(5) NOT NULL auto_increment,
src TEXT NOT NULL,
border varchar(3),
width varchar(4),
height varchar(4),
hspace varchar(4),
vspace varchar(4), 
alt varchar(30) DEFAULT NULL,
longdesc TEXT DEFAULT NULL,
PRIMARY KEY (id)
);

 

QUESTION 1 :

Trying the site http://www.e-gov.gr I take the error

 

Fatal error: Maximum execution time of 30 seconds exceeded in C:\wamp\www\php examples\example.php on line 56

 

What is happened ?

 

QUESTION 2 :

I tried the site of microsoft and because the src of img is in the end , I cannot find any images.

 

And Last QUESTION

I want to save also in database the line of code that I found the image so as in every row of table 'images' to see the line.

 

Thanks a lot

Link to comment
https://forums.phpfreaks.com/topic/122725-saving-images-into-database/
Share on other sites

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.