By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,744 Members | 1,696 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,744 IT Pros & Developers. It's quick & easy.

Uploads with MySQL

P: n/a
Troubles getting a file upload into a MySQL DB to work. Any help is

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"
<html xmlns="">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link rel="stylesheet" type="text/css" href="rstyle1.css" />
<div id="frame">
<div id="head">
<img src="./img/ps.jpg"/>
<div id="menu">
<font face="Comic Sans MS, Arial" size="+1" color="#FFFFFF"><font
color="#0099FF">view & edit album</font>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; add annotations
<div id="content"><font color="#FFFFFF"><center>
<h4>Add a picture.</h4><br/>
<form action="up.php" enctype="multipart/form-data" method="post">
<h4>Image name: </h4><input name="name" type="text"><br/>
<h4>Image(JPEG) to Upload</h4><input name="userfile" type="file"><br/><br/>
<input name="submit" type="submit">

} 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_file($userfile))
// Open the uploaded file
$file = fopen($userfile, "r");

// Read in the uploaded file
$fileContents =
fread($file, filesize($userfile));

// Escape special charcters in the file
$fileContents = AddSlashes($fileContents);
$fileContents = NULL;

$album = $HTTP_GET_VARS['albumname'];
if ((@ mysql_query ("INSERT INTO image VALUES (\"$name\", \"$fileCont
ents\", \"$album\", \"\")",
&& @ mysql_affected_rows() == 1) {
header("Location: up.php?" .
"sqlID=". mysql_insert_id($connection) .
else {
header("Location: up.php?" .
"status=F" . "&sql=" . mysql_error());

Jul 17 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.