Flo
|
| Posted: 07/16/2002, 10:08 AM |
|
I'm still looking for help about upload a file in a mysql blob field using php
Please help a poor french developper
|
|
|
 |
Themelis Cuiper
|
| Posted: 07/16/2002, 3:21 PM |
|
Hi Flo
i found this for you, hope you can use it
ps, did you know most phpinstalls do not use .gif
anymore in GD functions, you can use gif2png from http://www.tuxedo.org/~esr/gif2png/
next solution uses a tempfile to read the
data into the db
TINYBLOB: max 256 bytes
BLOB: max 65.537 bytes (64 KB)
MEDIUMBLOB: max 16.777.218 bytes (16 MB)
LONGBLOB: max 4.294.967.299 bytes (4 GB)
-----------------------------
CREATE TABLE images (
id INT not null AUTO_INCREMENT,
name VARCHAR (64) not null,
type VARCHAR (64) not null,
length INT not null,
content BLOB not null,
PRIMARY KEY (id)
)
---------------------
<?php
/* upload.php */
if ($submit) {
if ($HTTP_POST_FILES[file][tmp_name] != "none") {
$fp = @fopen($HTTP_POST_FILES[file][tmp_name],"r");
if ($fp) {
$content = fread($fp,filesize($HTTP_POST_FILES[file][tmp_name]));
fclose($fp);
$db = @mysql_connect("localhost","user","password") or Die(mysql_error());
@mysql_select_db("database_naam",$db) or Die("Error: " . mysql_error());
$sql = "INSERT INTO images VALUES(0,'" . $HTTP_POST_FILES[file][name] . "','" . $HTTP_POST_FILES[file][type] . "','" . filesize($HTTP_POST_FILES[file][tmp_name]) . "','" . addslashes($content) . "')";
@mysql_query($sql,$db) or Die(mysql_error());
mysql_close($db);
print "File Is Saved";
} else { /* if the file is not there !$fp */
print "could NOT open file";
}
} else {
print "no file selected";
}
} else { ?>
<html>
<head>
<title>Upload File</title>
</head>
<body>
<form action="upload.php" method="POST" enctype="multipart/form-data">
Bestand: <input type="file" name="file"> <input type="submit" name="submit" value="Upload">
</form>
</body>
<? } ?>
<?
If (filesize($HTTP_POST_FILES[file][tmp_name]) > 65537) { print “File TOO Big!”; }
?>
----------------------
<?
/* image.php */
if (!empty($id)) {
$db = @mysql_connect("localhost","user","password") or Die(mysql_error());
@mysql_select_db("database_naam",$db) or Die("Error: " . mysql_error());
$sql = "SELECT type,length,content FROM images WHERE id = '$id' LIMIT 0,1";
$result = @mysql_query($sql,$db) or Die(mysql_error());
while ($row = mysql_fetch_array($result)) {
Header("Content-Length: " . $row[length] . "\nContent-Type: " . $row[type]);
print $row[content];
}
mysql_close($db);
}
?>
----------------------------
have fun
Themelis
|
|
|
 |
musaab
|
| Posted: 07/16/2002, 5:07 PM |
|
I have a problem when doing this using ccs.I tried the example posted which written using cc but when i open it with ccs it does not convert right it seems that i loose the events. Who ever done it please share it with us........thanks
|
|
|
 |
|