So I've been trying to figure out how to store images in a mysql database, and as far as i can tell the images are stored but getting them out seems to be the problem.
when i try to go to the page on my webhost it says that
"Can not select the database: Access denied for user 'testimg'@'localhost' to database 'testImages'"
and when i goto show.php?id=1 on my local mamp install it gives me all kinds of weird symbols
ÿÀ�™Ì�ÿÄ�È���������������������������!1AQaq"2‘¡±BR#Ãbr‚’Ñ¢Â3CS$á²Òsƒ“%ðñc£Ã4â³T56Dtâ€E&Ód¤´ÄUu•7���!1AQaqð‘¡"2±ÃÑáñBRÂbr⢉#3ÿÚ���?�Ü/é -èÂ
i've checked everything in the code a million times and searched google and this forum for anything that can help me but i haven't been able to find something that has helped me understand what exactly is going on and why
heres the upload form
<form enctype="multipart/form-data" action="insert.php" method="post" name="changer">
<input name="MAX_FILE_SIZE" value="1500000" type="hidden">
<input name="image" accept="image/jpeg" type="file">
<input value="Submit" type="submit">
</form>
this is my insert.php that processes the image after its submitted
<?php
include './database.php';
$link = mysql_connect($host, $username, $password);
if (!$link) {
die('Could not connect: ' . mysql_error());
}
mysql_select_db ($database);
if (isset($_FILES['image']) && $_FILES['image']['size'] > 0) {
$tmpName = $_FILES['image']['tmp_name'];
$fp = fopen($tmpName, 'r');
$data = fread($fp, filesize($tmpName));
$data = addslashes($data);
fclose($fp);
$query = "INSERT INTO tbl_images ";
$query .= "(image) VALUES ('$data')";
$results = mysql_query($query, $link);
print "Thank you, your file has been uploaded.";
}else{
print "No image selected/uploaded";
}
mysql_close($link);
?>
and heres the show.php that displays the image using the id
<?php
include './database.php';
@mysql_connect($host, $username, $password) or die("Can not connect to database: ".mysql_error());
@mysql_select_db($database) or die("Can not select the database: ".mysql_error());
$id = $_GET['id'];
if(!isset($id) || empty($id)){
die("Please select your image!");
}else{
$query = mysql_query("SELECT image FROM tbl_images WHERE id='".$id."'");
$row = mysql_fetch_assoc($query);
$content = $row['image'];
header("Content-type: image/jpg");
echo $content;
}
?>
Form errors in an array
I'm processing a form and putting the errors in an array. empty($errors) doesn't seem to do the trick when trying to check to see if the array is empty. Is my understanding of empty()incorrect? Each
help understanding hidden input w/ php
hello i'm doing a tutorial where there are multiple forms for an edit page for a user to update their info... there's a section of the code i dont really understand how it works...here's code:php:if
output_buffering so rewrite
I'm planning to rewrite some of my scripts so they don't have to use output buffering to accomplish their form validation and html displays......so what rules should i follow when rewriting it so i
upload photo limits
ive got a upload photo script and im just trying to make more secure currently it limits size and as you can see from my code below it limits only gif and php fileshow do i edit my code to limit all
help with email script...
hey I need help with my mail scriptwhen the form on http://www.mcgdesignstudio.com/contact.html is filled out, it send the from with no errors.. however i never receive it.. my hosting company have
Save remote XML to local website folder
Hi, I hope you can help me out. I would like to be able to pull an XML file from another site and then store it in a local folder on my site. That way, I would only need to pull the xml file once in
Logic question
im wondering what's the best method to do the above list:it is for alliance @ MMORPG game -the administrator of alliance have 10 slots for creating ranks ... each rank have it's own permissions (in
Page doesn't expand for content
Hi. I've been testing a query I made. It's here http://lapr1.6te.net/inquerito.phpThe page doesn't expand for content, it cuts most of it. What can I do to solve this?Thanks
Something Non-Traditional. Can we solve?
I have an idea for an application here. It's mostly flash, but it couldn't work without a somewhat non-traditional php functionality.here's the thing:I want to have a function which returns an
How to know if online site made with PHP
Hello,I see some sites that does not display extensions at all , for example:www.site.com/login (for login page)but how I can know the language used in this site ?Thanks