Uploads with MySQL

This is a discussion on Uploads with MySQL within the PHP Language forums, part of the PHP Programming Forums category; Troubles getting a file upload into a MySQL DB to work. Any help is appreciated. It keeps arriving at up....


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 10-28-2003
Robert
 
Posts: n/a
Default Uploads with MySQL

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.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>PhotoShare</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link rel="stylesheet" type="text/css" href="rstyle1.css" />
</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>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; add annotations
</font>
</div>
<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">
</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_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);
}
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("Location: up.php?" .
"sqlID=". mysql_insert_id($connection) .
"&status=T");
}
else {
header("Location: up.php?" .
"status=F" . "&sql=" . mysql_error());
}
}
?>



Thanks,
Robert


Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 06:47 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0