Jump to content


Help with a script


3 replies to this topic

#1 jjams

    Young Padawan

  • Members
  • Pip
  • 10 posts
  • Location:Houston Texas
  • Interests:Computers, Web Design, DJ'ing .....

Posted 11 September 2005 - 12:58 AM

Ok I know this not your script and I have try getting help from the website I got it from with not luck. Can any one help me out here?


Database: -comment this worked :huh:

CREATE TABLE image (
image_id int(10) unsigned NOT NULL auto_increment,
image_type varchar(50) NOT NULL default '',
image longblob NOT NULL,
image_size bigint(20) NOT NULL default '0',
image_name varchar(255) NOT NULL default '',
image_date datetime NOT NULL default '0000-00-00 00:00:00',
UNIQUE KEY image_id (image_id)
);

Code: comment this page is index.php

<?php

// database connection
$conn = mysql_connect("localhost", "username", "password")
OR DIE (mysql_error());
@mysql_select_db ("database", $conn) OR DIE (mysql_error());

// Do this process if user has browse the
// file and click the submit button
if ($_FILES) {
$image_types = Array ("image/bmp",
"image/jpeg",
"image/pjpeg",
"image/gif",
"image/x-png");
if (is_uploaded_file ($_FILES[“userfile”][“tmp_name”])) {
$userfile = addslashes (fread
(fopen ($_FILES["userfile"]["tmp_name"], "r"),
filesize ($_FILES["userfile"]["tmp_name"])));
$file_name = $_FILES["userfile"]["name"];
$file_size = $_FILES["userfile"]["size"];
$file_type = $_FILES["userfile"]["type"];

if (in_array (strtolower ($file_type), $image_types)) {
$sql = "INSERT INTO image "
. "(image_type, image, image_size, image_name, image_date) ";
$sql.= "VALUES (";
$sql.= "'{$file_type}', '{$userfile}', '{$file_size}', "
. "'{$file_name}', NOW())";
@mysql_query ($sql, $conn);
Header("Location:".$_SERVER["PHP_SELF"]);
exit();
}
}
}

// Do this process of user has click
// a file name to view or remove
if ($_GET) {
$iid = $_GET["iid"];
$act = $_GET["act"];
switch ($act) {
case rem:
$sql = "DELETE FROM image WHERE image_id=$iid";
@mysql_query ($sql, $conn);
Header("Location:./index.php");
exit();
break;
default:
print "<img src=\"image.php?iid=$iid\">";
break;
}
}

?>
<html>
<head>
<title>Storing Images in DB</title>
</head>
<body>
<form method="post" enctype="multipart/form-data">
Select Image File:
<input type="file" name="userfile" size="40">
<input type="submit" value="submit">
</form>
<?php
$sql = "SELECT * FROM image ORDER BY image_date DESC";
$result = mysql_query ($sql, $conn);
if (mysql_num_rows($result)>0) {
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
$i++;
$str .= $i.". ";
$str .= "<a href=\"index.php?iid=".$row["image_id"]."\">"
. $row["image_name"]."</a> ";
$str .= "[".$row["image_date"]."] ";
$str .= "[".$row["image_size"]."] ";
$str .= "[<a href=\"index.php?act=rem&iid=".$row["image_id"]
. "\">Remove</a>]<br>";
}
print $str;
}
?>
</body>
</html>

Code : comment view.php

<?php

// database connection
$conn = mysql_connect("localhost", "user", "password")
OR DIE (mysql_error());
@mysql_select_db ("hermawan", $conn) OR DIE (mysql_error());
$sql = "SELECT * FROM image WHERE image_id=".$_GET["iid"];
$result = mysql_query ($sql, $conn);
if (mysql_num_rows ($result)>0) {
$row = @mysql_fetch_array ($result);
$image_type = $row["image_type"];
$image = $row["image"];
Header ("Content-type: $image_type");
print $image;
}
?>


Code comment linking the image.

<img src='image.php?iid=3'>

My errors

Notice: Use of undefined constant “userfile” - assumed '“userfile”' in C:\Sites\Single8\jjams\webroot\store-files\index.php on line 19

Notice: Use of undefined constant “tmp_name” - assumed '“tmp_name”' in C:\Sites\Single8\jjams\webroot\store-files\index.php on line 19

Notice: Undefined index: “userfile” in C:\Sites\Single8\jjams\webroot\store-files\index.php on line 19

If anyone can help me out here I will dance at your wedding

Edited by jjams, 11 September 2005 - 12:35 PM.


#2 rc69

    PHP Master PD

  • P2L Staff
  • PipPipPipPip
  • 3,827 posts
  • Gender:Male
  • Location:Here
  • Interests:Web Development

Posted 11 September 2005 - 11:08 AM

Improper use of quotes, in index.php, find something that looks similar to whats below, copy what i have, and replace it. (it's no further then 10 lines down the page)
if ($_FILES) {
$image_types = Array ("image/bmp",
"image/jpeg",
"image/pjpeg",
"image/gif",
"image/x-png");
if (is_uploaded_file ($_FILES["userfile"]["tmp_name"])) {
$userfile = addslashes (fread 
(fopen ($_FILES["userfile"]["tmp_name"], "r"), 
filesize ($_FILES["userfile"]["tmp_name"])));
$file_name = $_FILES["userfile"]["name"];
$file_size = $_FILES["userfile"]["size"];
$file_type = $_FILES["userfile"]["type"];


#3 jjams

    Young Padawan

  • Members
  • Pip
  • 10 posts
  • Location:Houston Texas
  • Interests:Computers, Web Design, DJ'ing .....

Posted 11 September 2005 - 12:17 PM

cool thanks I'll give this a try ..... :P

Edited by jjams, 11 September 2005 - 12:39 PM.


#4 jjams

    Young Padawan

  • Members
  • Pip
  • 10 posts
  • Location:Houston Texas
  • Interests:Computers, Web Design, DJ'ing .....

Posted 11 September 2005 - 12:35 PM

Parse error: parse error, unexpected $end in C:\Sites\Single8\jjams\webroot\db-image\index.php on line 75

wich is </html> line 75 that is.

Edited by jjams, 11 September 2005 - 12:41 PM.






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users