Ik zit nu al de hele dag mijn haren van me kop te trekken om een afbeelding met een script in mijn database te krijgen.
Dit is de script:
<?php
// store.php3 - by Florian Dittmer <[email protected]>
// Example php script to demonstrate the storing of binary files into
// an sql database. More information can be found at http://www.phpbuilder.com/
?>
<html>
<head><title>Store binary data into SQL Database</title></head>
<body>
<?php
// code that will be executed if the form has been submitted:
if ($submit){
// connect to the database
// (you may have to adjust the hostname,username or password)
MYSQL_CONNECT("localhost","root","password");
mysql_select_db("binary_data");
$data = addslashes(fread(fopen($form_data, "r"), filesize($form_data)));
$result=MYSQL_QUERY("INSERT INTO binary_data (description,bin_data,filename,filesize,filetype) ".
"VALUES ('$form_description','$data','$form_data_name','$form_data_size','$form_data_type')");
$id= mysql_insert_id();
print "<p>This file has the following Database ID: <b>$id</b>";
MYSQL_CLOSE();
}
else {
// else show the form to submit new data:
?>
<form method="post" action="<?php echo $PHP_SELF; ?>" enctype="multipart/form-data">
File Description:<br>
<input type="text" name="form_description" size="40">
<input type="hidden" name="MAX_FILE_SIZE" value="1000000">
<br>File to upload/store in database:<br>
<input type="file" name="form_data" size="40">
<p><input type="submit" name="submit" value="submit">
</form>
<?php
}
?>
</body>
</html>
<?php
// getdata.php3 - by Florian Dittmer <[email protected]>
// Example php script to demonstrate the direct passing of binary data
// to the user. More infos at http://www.phpbuilder.com
// Syntax: getdata.php3?id=<id>
if($id) {
// you may have to modify login information for your database server:
@MYSQL_CONNECT("localhost","root","password");
@mysql_select_db("binary_data");
$query = "select bin_data,filetype from binary_data where id=$id";
$result = @MYSQL_QUERY($query);
$data = @MYSQL_RESULT($result,0,"bin_data");
$type = @MYSQL_RESULT($result,0,"filetype");
Header( "Content-type: $type");
echo $data;
};
?>
Ik draai het netjes in localhost en heb alles goed ingesteld, inclusief mijn database, maar als ik de pagina al open krijg ik de message over dat de if ($submit) undefined is. Het lukt dus voor geen meter. Als ik toch een afbeelding selecteer en op submit klik krijg ik het volgende:
Object niet gevonden!
De gevraagde URL was niet gevonden op deze server. De link op deze pagina pagina is verkeerd of achterhaald. Gelieve de auteur van die pagina in te lichten over deze fout.
Indien u van oordeel bent dat deze server in fout is, gelieve de webmaster te contacteren.
Error 404
localhost
10-10-2011 22:24:05
Apache/2.2.17 (Win32) mod_ssl/2.2.17 OpenSSL/0.9.8o PHP/5.3.4 mod_perl/2.0.4 Perl/v5.10.1
In de url balk staat ook iets raars als ik deze ERROR krijg, namelijk:
http://localhost/test/img_upload/%3Cbr%20/%3E%3Cb%3ENotice%3C/b%3E:%20%20Undefined%20variable:%20PHP_SELF%20in%20%3Cb%3ED:%5CProgram%20Files%5Cxampp%5Chtdocs%5Ctest%5Cimg_upload%5Cstore.php%3C/b%3E%20on%20line%20%3Cb%3E39%3C/b%3E%3Cbr%20/%3E
Ik snap er helemaal niks van, wie helpt me verder?
Alvast bedankt!
Mvg,
Piet