Troubles getting a file upload into a MySQL DB to work. Any help is
appreciated.
It keeps arriving at up.php without any get data, but has worked before.
It's unpredictable based on slight form and php variations, I can't get it
running smoothly again.
<?php if (empty($image) || empty($userfile ))
{
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>PhotoSha re</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link rel="stylesheet " type="text/css" href="rstyle1.c ss" />
</head>
<body>
<div id="frame">
<div id="head">
<img src="./img/ps.jpg"/>
</div>
<div id="menu">
<font face="Comic Sans MS, Arial" size="+1" color="#FFFFFF" ><font
color="#0099FF" >view & edit album</font>
&nb sp; add annotations
</font>
</div>
<div id="content"><f ont color="#FFFFFF" ><center>
<h4>Add a picture.</h4><br/>
<form action="up.php" enctype="multip art/form-data" method="post">
<h4>Image name: </h4><input name="name" type="text"><br/>
<h4>Image(JPE G) to Upload</h4><input name="userfile" type="file"><br/><br/>
<input name="submit" type="submit">
</form>
</center></font></div>
</div>
</body>
</html>
<?php
} else {
$connection = mysql_connect ("localhost" , "USERNAME", "PASS") or die ('I
cannot connect to the database because: ' . mysql_error());
mysql_select_db ("DATABASE", $connection);
if (is_uploaded_fi le($userfile))
{
// Open the uploaded file
$file = fopen($userfile , "r");
// Read in the uploaded file
$fileContents =
fread($file, filesize($userf ile));
// Escape special charcters in the file
$fileContents = AddSlashes($fil eContents);
}
else
$fileContents = NULL;
$album = $HTTP_GET_VARS['albumname'];
if ((@ mysql_query ("INSERT INTO image VALUES (\"$name\", \"$fileCont
ents\", \"$album\", \"\")",
$connection))
&& @ mysql_affected_ rows() == 1) {
header("Locatio n: up.php?" .
"sqlID=". mysql_insert_id ($connection) .
"&status=T" );
}
else {
header("Locatio n: up.php?" .
"status=F" . "&sql=" . mysql_error());
}
}
?>
Thanks,
Robert
appreciated.
It keeps arriving at up.php without any get data, but has worked before.
It's unpredictable based on slight form and php variations, I can't get it
running smoothly again.
<?php if (empty($image) || empty($userfile ))
{
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>PhotoSha re</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link rel="stylesheet " type="text/css" href="rstyle1.c ss" />
</head>
<body>
<div id="frame">
<div id="head">
<img src="./img/ps.jpg"/>
</div>
<div id="menu">
<font face="Comic Sans MS, Arial" size="+1" color="#FFFFFF" ><font
color="#0099FF" >view & edit album</font>
&nb sp; add annotations
</font>
</div>
<div id="content"><f ont color="#FFFFFF" ><center>
<h4>Add a picture.</h4><br/>
<form action="up.php" enctype="multip art/form-data" method="post">
<h4>Image name: </h4><input name="name" type="text"><br/>
<h4>Image(JPE G) to Upload</h4><input name="userfile" type="file"><br/><br/>
<input name="submit" type="submit">
</form>
</center></font></div>
</div>
</body>
</html>
<?php
} else {
$connection = mysql_connect ("localhost" , "USERNAME", "PASS") or die ('I
cannot connect to the database because: ' . mysql_error());
mysql_select_db ("DATABASE", $connection);
if (is_uploaded_fi le($userfile))
{
// Open the uploaded file
$file = fopen($userfile , "r");
// Read in the uploaded file
$fileContents =
fread($file, filesize($userf ile));
// Escape special charcters in the file
$fileContents = AddSlashes($fil eContents);
}
else
$fileContents = NULL;
$album = $HTTP_GET_VARS['albumname'];
if ((@ mysql_query ("INSERT INTO image VALUES (\"$name\", \"$fileCont
ents\", \"$album\", \"\")",
$connection))
&& @ mysql_affected_ rows() == 1) {
header("Locatio n: up.php?" .
"sqlID=". mysql_insert_id ($connection) .
"&status=T" );
}
else {
header("Locatio n: up.php?" .
"status=F" . "&sql=" . mysql_error());
}
}
?>
Thanks,
Robert