Hello, I have a big problem. I have the following code but it just doesn't want to display my picture, it displays a small area without a picture, submitting and deleteng the image is working, but displaying...DOESN'T :(
//2.php -
<?php
-
-
// database connection
-
$conn = mysql_connect("localhost", "root", "triadpass") OR DIE (mysql_error());
-
@mysql_select_db ("Books", $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");
-
-
$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_data, 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:./2.php");
-
exit();
-
break;
-
default:
-
echo "<img src=\"immage.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=\"2.php?iid=".$row["image_id"]."\">".$row["image_name"]."</a> ";
-
$str .= "[".$row["image_date"]."] ";
-
$str .= "[".$row["image_size"]."] ";
-
$str .= "[<a href=\"2.php?act=rem&iid=".$row["image_id"]."\">Remove</a>]<br>";
-
}
-
print $str;
-
}
-
?>
-
</body>
-
</html>
-
[Please use CODE tags when posting source code. Thanks! --pbmods]
//immage.php -
<?php
-
-
// database connection
-
$conn = mysql_connect("localhost", "root", "triadpass") OR DIE (mysql_error());
-
$mysql_select_db ("Books", $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_data"];
-
Header ("Content-type: $image_type");
-
print $image;
-
}
-
?>
1 2280
Split from original thread, merged duplicate posts.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Alper Adatoz |
last post by:
Hi,
i have a little problem. i hope u guys give me a clear solution (:
db: mssql
i just want to put jpeg file to the image field at the mssql db.
and after that i want to call it back..
|
by: dave |
last post by:
Hello there,
I am at my wit's end ! I have used the following script succesfully to
upload an image to my web space. But what I really want to be able to do is
to update an existing record in a...
|
by: theonlydrayk |
last post by:
the script that show image is :
<?php
include('dbinfo.inc.php');
mysql_connect($localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query =...
|
by: William Drew |
last post by:
REQUEST FOR DISCUSSION (RFD)
unmoderated group comp.databases.mysql
This is an invitation to discuss the following proposal to create newsgroup
comp.databases.mysql. Please note that YOU...
|
by: Mike Chirico |
last post by:
Interesting Things to Know about MySQL
Mike Chirico (mchirico@users.sourceforge.net)
Copyright (GPU Free Documentation License) 2004
Last Updated: Mon Jun 7 10:37:28 EDT 2004
The latest...
|
by: John Smith |
last post by:
I know that uploading an image to a database has been covered, oh, about 3
trillion times. However, I haven't found anything covering uploading to a
MySQL database with .net. Please don't...
|
by: Good Man |
last post by:
Hi there
I've noticed some very weird things happening with my current MySQL setup
on my XP Laptop, a development machine.
For a while, I have been trying to get the MySQL cache to work....
|
by: josh.kuo |
last post by:
Sorry about the subject, I can't think of a better one.
I recently wrote some PHP classes that I think might be of interest to
this group. Since I have been reaping the benefits of reading news...
|
by: mpar612 |
last post by:
Hi everyone,
I'm not sure if this is asking too much or not. I am trying to get the
following PHP code to work on my website. It utilizes PHP 5, MySQL 4.1
and the PEAR DB module.
I am...
|
by: dac |
last post by:
I am quietly going insane on this project. I've never worked on a project like this one before. All my previous sticky forms were for data entry, not editing. I don't know how to display the form...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
| |