string afbeelding in database zetten

Overzicht Reageren

Sponsored by: Vacatures door Monsterboard

Harry Schaten

Harry Schaten

12/09/2011 14:45:53
Quote Anchor link
Hallo allemaal

Ik hoop dat iemand me zou kunnen helpen.

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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
<?php  
// filename: upload.processor.php

// first let's set some variables

// make a note of the current working directory, relative to root.

$directory_self = str_replace(basename($_SERVER['PHP_SELF']), '', $_SERVER['PHP_SELF']);

// make a note of the directory that will recieve the uploaded files
$uploadsDirectory = $_SERVER['DOCUMENT_ROOT'] . $directory_self . 'uploaded_files/';

// make a note of the location of the upload form in case we need it
$uploadForm = 'http://' . $_SERVER['HTTP_HOST'] . $directory_self . 'upload.form.php';

// make a note of the location of the success page
$uploadSuccess = 'http://' . $_SERVER['HTTP_HOST'] . $directory_self . 'upload.success.php';

// name of the fieldname used for the file in the HTML form
$fieldname = 'naam';

// Now let's deal with the upload

// possible PHP upload errors    

$errors = array(1 => 'php.ini bestand is te groot',
                2 => 'Te groot bestand',
                3 => 'Bestand gedeeltelijk aangekomen',
                4 => 'Geen bestand');
// check the upload form was actually submitted else print form
isset($_POST['submit'])
    or error('Druk op de knop', $uploadForm);

// check for standard uploading errors
($_FILES[$fieldname]['error'] == 0)
    or error($errors[$_FILES[$fieldname]['error']], $uploadForm);

// check that the file we are working on really was an HTTP upload
@is_uploaded_file($_FILES[$fieldname]['tmp_name'])
    or error('not an HTTP upload', $uploadForm);

// validation... since this is an image upload script we
// should run a check to make sure the upload is an image

@getimagesize($_FILES[$fieldname]['tmp_name'])
    or error('alleen afbeeldingen kunnen worden geupload', $uploadForm);
    
// make a unique filename for the uploaded file and check it is
// not taken... if it is keep trying until we find a vacant one

$now = time();
while(file_exists($uploadFilename = $uploadsDirectory.$now.'-'.$_FILES[$fieldname]['name']))
{

    $now++;
}


// now let's move the file to its final and allocate it with the new filename
@move_uploaded_file($_FILES[$fieldname]['tmp_name'], $uploadFilename)
    or error('kan niet storen', $uploadForm);

// If you got this far, everything has worked and the file has been successfully saved.
// We are now going to redirect the client to the success page.

header('Location: ' . $uploadSuccess);

// make an error handler which will be used if the upload fails
function error($error, $location, $seconds = 5)
{

    header("Refresh: $seconds; URL=\"$location\"");
    echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"'."\n".
    '"http://www.w3.org/TR/html4/strict.dtd">'."\n\n".
    '<html lang="en">'."\n".
    '    <head>'."\n".
    '        <meta http-equiv="content-type" content="text/html; charset=iso-8859-1">'."\n\n".
    '        <link rel="stylesheet" type="text/css" href="stylesheet.css">'."\n\n".
    '    <title>Upload error</title>'."\n\n".
    '    </head>'."\n\n".
    '    <body>'."\n\n".
    '    <div id="Upload">'."\n\n".
    '        <h1>Upload faalt</h1>'."\n\n".
    '        <p>Error: '."\n\n".
    '        <span class="red">' . $error . '...</span>'."\n\n".
    '         Probeer het opnieuw. U word teruggestuurd</p>'."\n\n".
    '     </div>'."\n\n".
    '</html>';
    exit;
}
// end error handler

include('connect_db.php');

if ( mysqli_num_rows($result) >0)
    {

        echo "het door u ingevulde bestaat al";
    }

else
{
    $query = "INSERT INTO `photos`.`producten` (`id`,
                                                `naam`,
                                                `onderwerp`,
                                                `tekst`)
                                        VALUES (Null,
                                                '"
.$location."',
                                                '"
.$_POST['onderwerp']."',
                                                '"
.$_POST['tekst']."');";
    mysqli_query($db, $query) or die ('de insert-query is niet goed uitgevoerd');
    echo "alles is in de database aangekomen";
}

?>


het procces script

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
<?php

// filename: upload.form.php

// first let's set some variables

// make a note of the current working directory relative to root.

$directory_self = str_replace(basename($_SERVER['PHP_SELF']), '', $_SERVER['PHP_SELF']);

// make a note of the location of the upload handler
$uploadHandler = 'http://' . $_SERVER['HTTP_HOST'] . $directory_self . 'upload.processor.php';

// set a max file size for the html upload form
$max_file_size = 90009000; // size in bytes

// now echo the html page

?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">

<html lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1">

<link rel="stylesheet" type="text/css" href="stylesheet.css">

<title>Upload</title>

</head>

<body>

<form id="Upload" action="
Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
<?php echo $uploadHandler ?>
" enctype="multipart/form-data" method="post">

<h1>
Upload formulier
</h1>

<p>
<input type="hidden" name="MAX_FILE_SIZE" value="
Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
<?php echo $max_file_size ?>
">
</p>

<p>
<label for="naam">Kies hier het bestand:</label>
<input id="naam" type="file" name="naam">
</p>

<p>
<label for="onderwerp">Onderwerp:</label>
<input type='text' name='onderwerp' size='30'/>
</p>
<p>
<label for="tekst">Kleine beschrijving:</label>
<input type='text' name='tekst' size='30'/>
</p>
<p>

<center><input id="submit" type="submit" name="submit" value="Uploaden maar"></center>
</p>

</form>


</body>

</html>

Het formulier.

Hoe kan ik de string(mapnaam/filename) naar de database wegschrijven?

groeten

Toevoeging op 12/09/2011 15:14:25:

Ik heb het al opgelost. Ik heb de code in de onderste query in de processor al veranderd in

$query = "INSERT INTO `photos`.`producten` (`id`,
`naam`,
`onderwerp`,
`tekst`)
VALUES (Null,
'".$_FILES["naam"]["name"]."',
'".$_POST['onderwerp']."',
'".$_POST['tekst']."');";
mysqli_query($db, $query) or die ('de insert-query is niet goed uitgevoerd');
echo "alles is in de database aangekomen";
 
PHP hulp

PHP hulp

23/12/2024 07:49:28
 
Jacco Brandt

Jacco Brandt

12/09/2011 15:41:15
Quote Anchor link
Waarmee zouden we je moeten helpen?
 
Ozzie PHP

Ozzie PHP

12/09/2011 15:44:12
Quote Anchor link
@Jacco, zie onderaan het bericht.. het is al opgelost ;)
 
Harry Schaten

Harry Schaten

12/09/2011 15:45:47
Quote Anchor link
Het is inderdaad al opgelost. Alleen wat hulp bij het uitlezen zou wel fijn zijn. Moet ik dan een nieuw topic maken?
 



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.