CodeCharge Studio
search Register Login  

Web Reporting

Visually create Web Reports in PHP, ASP, .NET, Java, Perl and ColdFusion.
CodeCharge.com

YesSoftware Forums -> Archive -> GotoCode Archive

 PHP Upload Please help a poor french developper !

Print topic Send  topic

Author Message
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

   


These are Community Forums for users to exchange information.
If you would like to obtain technical product help please visit http://support.yessoftware.com.

Web Database

Join thousands of Web developers who build Web applications with minimal coding.
CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


Powered by UltraApps Forum created with CodeCharge Studio
Copyright © 2003-2004 by UltraApps.com  and YesSoftware, Inc.