Page 1 of 1

Images PHP/MySQL

Posted: Sat Dec 06, 2003 2:11 pm
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

Posted: Sat Dec 06, 2003 2:37 pm
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.

my script

Posted: Sat Dec 06, 2003 3:34 pm
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);
?>

Posted: Sat Dec 06, 2003 4:18 pm
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