Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.

Problem kod ubacivanja slike u MySQL bazu

[es] :: PHP :: Problem kod ubacivanja slike u MySQL bazu

[ Pregleda: 2562 | Odgovora: 3 ] > FB > Twit

Postavi temu Odgovori

Autor

Pretraga teme: Traži
Markiranje Štampanje RSS

Meklaud
Danko Miocinovic
Blizu

Član broj: 6604
Poruke: 39
*.adsl-2.sezampro.yu.

ICQ: 103744801


+1 Profil

icon Problem kod ubacivanja slike u MySQL bazu04.03.2008. u 23:18 - pre 195 meseci
Pozdrav svima,

Nov sam u ovome, pa imam neki problem koji ocigledno ne vidim, pa moram da pitam.

Hteo sam da ubacim sliku u bazu.
Ali, ne da se slika, tj. ja je ne vidim u bazi sto znaci da kod ne radi.
Evo i koda pa molim za pomoc.

Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
<html>
    <head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>File upload</title>
</head>

<body>
<form action="" method="post" enctype="multipart/form-data" name="uploadImage" id="uploadImage"> 
    <p>
        <label for="image">Upload image:</label>
        <input type="file" name="image" id="image" />
        <input type="hidden" name="MAX_FILE_SIZE" value="96000">
    </p>
    <p>
        <input type="submit" name="upload" id="upload" value="Upload" />
    </p>
</form>



      <?php
    // check if a file was submitted
    if(!isset($_FILES['image'])) {
        echo '<p>Please select a file</p>';
    }
    else
        {
        try {
            upload();
            // give praise and thanks to the php gods
            echo '<p>Thank you for submitting</p>';
        }
        catch(Exception $e) {
            echo $e->getMessage();
            echo 'Sorry, could not upload file';
        }
    }
function upload(){
 
    if(is_uploaded_file($_FILES['image']['tmp_name'])) {
 
        // check the file is less than the maximum file size
        if($_FILES['image']['size'] < $maxsize)
            {
        // prepare the image for insertion
        $imgData =addslashes (file_get_contents($_FILES['image']['tmp_name']));
        // $imgData = addslashes($_FILES['image']);
 
        // get the image info..
          $size = getimagesize($_FILES['image']['tmp_name']);
 
        // put the image in the db...
          // database connection
          mysql_connect("localhost", "root", "boba") OR DIE (mysql_error());
 
          // select the db
          mysql_select_db ("test") OR DIE ("Unable to select db".mysql_error());
 
        // our sql query
        $sql = "INSERT INTO testblob
                ( image_id , image_type ,image, image_size, image_name)
                VALUES
                ('', '{$size['mime']}', '{$imgData}', '{$size[3]}', '{$_FILES['image']['name']}')";
 
        // insert the image
        if(!mysql_query($sql)) {
            echo 'Unable to upload file';
            }
        }
    }
    else {
         // if the file is not less than the maximum allowed, print an error
         echo
          '<div>File exceeds the Maximum File limit</div>
          <div>Maximum File limit is '.$maxsize.'</div>
          <div>File '.$_FILES['image']['name'].' is '.$_FILES['image']['size'].' bytes</div>
          <hr />';
         }
    }
?>
    </body>
</html>




Kad ja ovo ucitam, otvori mi se forma i ja uradim upload slike od 19KB i on mi lepo kaze thank you for submitting. Naravno slike nema u bazi, tj. ja ne vidim tamo blob.
Pomoc.

Hvala




[Ovu poruku je menjao Nemanja Avramović dana 05.03.2008. u 01:47 GMT+1]
D
 
Odgovor na temu

Man-Wolf
Mihailo Joksimovic
Beograd

Član broj: 17016
Poruke: 873
*.eunet.yu.



+13 Profil

icon Re: Problem kod ubacivanja slike u MySQL bazu05.03.2008. u 12:29 - pre 195 meseci
Aj probaj ovaj kod ( meni radi ):

Code:

<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body>
<form method="post" enctype="multipart/form-data">
<table width="350" border="0" cellpadding="1" cellspacing="1" class="box">
<tr>
<td width="246">
<input type="hidden" name="MAX_FILE_SIZE" value="2000000">
<input name="userfile" type="file" id="userfile">
</td>
<td width="80"><input name="upload" type="submit" class="box" id="upload" value=" Upload "></td>
</tr>
</table>
</form>
</body>
</html>

<?php
if(isset($_POST['upload']) && $_FILES['userfile']['size'] > 0)
{
$fileName = $_FILES['userfile']['name'];
$tmpName  = $_FILES['userfile']['tmp_name'];
$fileSize = $_FILES['userfile']['size'];
$fileType = $_FILES['userfile']['type'];

$fp      = fopen($tmpName, 'r');
$content = fread($fp, filesize($tmpName));
$content = addslashes($content);
fclose($fp);

if(!get_magic_quotes_gpc())
{
    $fileName = addslashes($fileName);
}

$link = @mysql_connect("localhost", "root", "boba") OR DIE (mysql_error());
@mysql_select_db ("test") OR DIE ("Unable to select db".mysql_error());

$query = "INSERT INTO testblob  (image_name, image_size, image_type, image) ".
"VALUES ('$fileName', '$fileSize', '$fileType', '$content')";

mysql_query($query) or die('Greska! Upit neuspesan');


echo "<br>File $fileName uploadovan!<br>";
}
?>
 
Odgovor na temu

Meklaud
Danko Miocinovic
Blizu

Član broj: 6604
Poruke: 39
*.ns.ac.yu.

ICQ: 103744801


+1 Profil

icon Re: Problem kod ubacivanja slike u MySQL bazu05.03.2008. u 14:46 - pre 195 meseci
Hvala na odgovoru, probacu pa cu javiti jesam li se izbazao ili nisam.
D
 
Odgovor na temu

Meklaud
Danko Miocinovic
Blizu

Član broj: 6604
Poruke: 39
*.ns.ac.yu.

ICQ: 103744801


+1 Profil

icon Re: Problem kod ubacivanja slike u MySQL bazu06.03.2008. u 13:11 - pre 195 meseci
Evo u cemu je bio problem:

bilo je problema sa konektovanjem na bazu zbog toga sto se zahteva drugaciji password posto MySQL pre verzije 4.1 ima drugaciji hashing.

Client does not support authentication protocol requested
by server; consider upgrading MySQL client

Ovo se dobije kad se pokusa izvrsavanje PHP skripte.

Objasnjenje i resenje problema se moze naci na sledecoj stranici:

hxxp://dev.mysql.com/doc/refman/5.0/en/password-hashing.html

Resen problem.


D
 
Odgovor na temu

[es] :: PHP :: Problem kod ubacivanja slike u MySQL bazu

[ Pregleda: 2562 | Odgovora: 3 ] > FB > Twit

Postavi temu Odgovori

Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.