Foto uit Database halen

Overzicht Reageren

Sponsored by: Vacatures door Monsterboard

Niels van Dijk

Niels van Dijk

23/09/2009 21:36:00
Quote Anchor link
Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?php
//connect to database. Username and password need to be changed
mysql_connect("localhost", "username", "password");

//Select database, database_name needs to be changed
mysql_select_db("menu_cms");

if (!$_POST['uploaded']){
//If nothing has been uploaded display the form
?>


<form action="<? echo $_SERVER['PHP_SELF']; ?>" method="post"
ENCTYPE="multipart/form-data">
Upload:<br><br>
<input type="file" name="image"><br><br>
<input type="hidden" name="uploaded" value="1">
<input type="submit" value="Upload">
</form>

<?
}else{
//if the form hasn't been submitted then:

//from here onwards, we are copying the file to the directory you made earlier, so it can then be moved
//into the database. The image is named after the persons IP address until it gets moved into the database

//get users IP

$ip=$REMOTE_ADDR;

//don't continue if an image hasn't been uploaded
if (!empty($image)){

//copy the image to directory
copy($image, "./temporary/".$ip."");

//open the copied image, ready to encode into text to go into the database
$filename1 = "./temporary/".$REMOTE_ADDR;
$fp1 = fopen($filename1, "r");

//record the image contents into a variable
$contents1 = fread($fp1, filesize($filename1));

//close the file
fclose($fp1);

//encode the image into text
$encoded = chunk_split(base64_encode($contents1));

//insert information into the database
mysql_query("INSERT INTO images (img,data)"."VALUES ('NULL', '$encoded')");

//delete the temporary file we made
unlink($filename1);
}


//end
}
?>


ik krijg deze error
"Parse error: parse error in C:\wamp\www\siteCMS\admin\foto_upload\upload.php on line 58"

ik zie het niet? jullie
 
PHP hulp

PHP hulp

26/04/2024 05:34:40
 
Roeltje M

Roeltje M

23/09/2009 21:45:00
Quote Anchor link
Als je eens met Tabs gaat werken zou het wat overzichtelijker zijn en zou je waarschijnlijk ook zo de fout kunnen vinden.
 
Niels van Dijk

Niels van Dijk

23/09/2009 21:53:00
Quote Anchor link
Hmm ja maar ik zie het niet
 
Jan Koehoorn

Jan Koehoorn

23/09/2009 22:08:00
Quote Anchor link
Ik zie dat je de file gewoon binair in de DB zet. Waarom wil je dat? Het is namelijk bijna nooit nodig om images rechtstreeks in je DB te zetten, tenzij je vergelijkingen op bit-niveau wilt doen.
 
Niels van Dijk

Niels van Dijk

23/09/2009 22:28:00
Quote Anchor link
Weet jij dan waar ik een tut of script kan vinden dat ik een img naar een map upload en dat is dat weer in mijn mysql kan terug vinden
 
Jan Koehoorn

Jan Koehoorn

23/09/2009 22:32:00
Quote Anchor link
Heel simpel; je zet gewoon de bestandsnaam in je database. Als je het plaatje op een pagina nodig hebt, sleutel je het goede pad in elkaar. Als je wilt kan ik wel een voorbeeldje maken, maar dan moet je nog wel ff online blijven.
 
Niels van Dijk

Niels van Dijk

23/09/2009 22:35:00
Quote Anchor link
tot een uur of 2 a 3 ik heb verder geen leven hahaha
 
Jan Koehoorn

Jan Koehoorn

23/09/2009 22:46:00
Quote Anchor link
Voorbeeld:
Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?php
    if ($_SERVER['REQUEST_METHOD'] == 'POST') {
        if ($_FILES['error'] == 0) {
            $tmp = $_FILES['userfile']['tmp_name'];
            if (is_uploaded_file ($tmp)) {
                $name = preg_replace ('/[^a-zA-z\.]/', '', $_FILES['userfile']['name']);
                // in mijn voorbeeld heet de map 'gfx' en heeft de goede rechten gekregen met chmod
                $path = $_SERVER['DOCUMENT_ROOT'] . '/gfx/';
                if (move_uploaded_file ($tmp, $path . $name)) {
                    $msg = '<p>Geupload: ' . $name . '</p>';
                    $msg .= '<p><img src="gfx/' . $name . '" /></p>';
                    // hier moet absoluut beveiling tegen MySQL injection op
                    // dus minstens mysql_real_escape_string () over $name heen halen

                    $sql = "
                        INSERT INTO tabelnaam
                        (filename)
                        VALUES
                        ('"
. $name . "')
                    "
;
                    $msg .= '<pre>' . print_r (htmlentities ($sql), true) . '</pre>';
                }
            }
        }
    }

?>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title>PHP Image Upload</title>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        
        <style type="text/css" media="screen">
            div#container                        {margin: 30px auto; width: 500px; padding: 10px;}
            
            input,
            div#container                        {font: 11px "Lucida Sans Unicode";}
            h1                                    {font: bold 11px "Lucida Sans Unicode";}        
        </style>
    </head>
    
    <body>
        <div id="container">
            <h1>PHP Image Upload</h1>
            <?php
                if (isset ($msg)) {
                    echo $msg;
                }

            ?>

            <form method="post" action="image_upload.php" enctype="multipart/form-data">
                <div>
                    <input id="userfile" name="userfile" type="file" />
                    <input type="submit" value="upload" />
                </div>
            </form>
        </div>
    </body>
</html>
 
Niels van Dijk

Niels van Dijk

23/09/2009 23:00:00
Quote Anchor link
sorry maar de Database ? ik snap het niet helemaal ik heb het voor elkaar dat hij nu dit aangeeft


Notice: Undefined index: error in C:\wamp\www\siteCMS\admin\foto_upload\image_upload.php on line 4

Notice: Undefined variable: menu_foto in C:\wamp\www\siteCMS\admin\foto_upload\image_upload.php on line 19
PHP Image Upload

Geupload: IMG_.jpg



INSERT INTO menu
(filename)
VALUES
('')
 



Overzicht Reageren

 
 

Om de gebruiksvriendelijkheid van onze website en diensten te optimaliseren maken wij gebruik van cookies. Deze cookies gebruiken wij voor functionaliteiten, analytische gegevens en marketing doeleinden. U vindt meer informatie in onze privacy statement.