Images PHP/MySQL

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
shaunmckinnon
Forum Newbie
Posts: 5
Joined: Sat Dec 06, 2003 2:11 pm

Images PHP/MySQL

Post by shaunmckinnon »

Hi:

Here's the thing:
I have a client who wishes to be able to upload an item picture with a description and a price, plus a link. I realize this is probably the most simplest script in the universe, but I know nothing about php scripting. I'm using phpmyadmin to create the database, and dreamweaver mx to interac with the database. My database is hosted remotely. If anyone can give me suggestions, or even an example script, it'd be greatly appreciated.

Yours truly,
PHPdumdum
User avatar
uberpolak
Forum Contributor
Posts: 261
Joined: Thu Jan 02, 2003 10:37 am
Location: Next to the bar

Post by uberpolak »

Perhaps you should post this in the volunteer/help wanted forum, and someone might whip you up a script. Alternatively, you could check http://www.hotscripts.com/ for a script to do what you're looking for.
shaunmckinnon
Forum Newbie
Posts: 5
Joined: Sat Dec 06, 2003 2:11 pm

my script

Post by shaunmckinnon »

Here's what I've done for a script, but it only outputs text...i'm not getting my picture.

Code: Select all

<?php require_once('../Connections/MySQL.php'); ?>
<?php
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}

$editFormAction = $HTTP_SERVER_VARS['PHP_SELF'];
if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {
  $editFormAction .= "?" . $HTTP_SERVER_VARS['QUERY_STRING'];
}

if ((isset($HTTP_POST_VARS["MM_insert"])) && ($HTTP_POST_VARS["MM_insert"] == "form1")) {
  $insertSQL = sprintf("INSERT INTO picturetest (picture) VALUES (%s)",
                       GetSQLValueString($HTTP_POST_VARS['picture'], "text"));

  mysql_select_db($database_MySQL, $MySQL);
  $Result1 = mysql_query($insertSQL, $MySQL) or die(mysql_error());
}

mysql_select_db($database_MySQL, $MySQL);
$query_picture = "SELECT * FROM picturetest";
$picture = mysql_query($query_picture, $MySQL) or die(mysql_error());
$row_picture = mysql_fetch_assoc($picture);
$totalRows_picture = mysql_num_rows($picture);
?>
<html>
<head>
<title>Picture</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<p>Upload Picture Tester</p>
<p></p>

<form method="post" name="form1" action="<?php echo $editFormAction; ?>">
  <table align="center">
    <tr valign="baseline">
      <td nowrap align="right">Picture:</td>
      <td><input type="file" name="picture" value="" size="32">
      </td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right">&nbsp;</td>
      <td><input type="submit" value="Insert Record">
      </td>
    </tr>
  </table>
  <input type="hidden" name="MM_insert" value="form1">
</form>
<p><?php echo $row_picture['picture']; ?></p>
</body>
</html>
<?php
mysql_free_result($picture);
?>
Cruzado_Mainfrm
Forum Contributor
Posts: 346
Joined: Sun Jun 15, 2003 11:22 pm
Location: Miami, FL

Post by Cruzado_Mainfrm »

u have to create a separate file, for ex image.php that gets the image from the database, and sets the header for an image, like this:

Code: Select all

<?php
<?php
header("Content-type: Application/Jpeg");
echo $imagedata;
?>
?>
be sure not to leave any spaces or text before the <?php or the image won't show
Post Reply