
fredted40x
Members-
Posts
34 -
Joined
-
Last visited
Never
Profile Information
-
Gender
Not Telling
fredted40x's Achievements

Member (2/5)
0
Reputation
-
Retrieving image from database (BLOB)? Just getting binary.
fredted40x replied to fredted40x's topic in PHP Coding Help
Solved! Found out i didnt need any " or '. echo "<img src=getoutside.php?id=$r[apartmentId]>"; worked . Thanks for helping p.s. cant find the soled button now -
Retrieving image from database (BLOB)? Just getting binary.
fredted40x replied to fredted40x's topic in PHP Coding Help
Thanks again for replying. That line seems to work but without errors now but im still getting a white box with a cross in it. Its says the location for the image is http://localhost/webs/getoutside.php?id='".15. and if i remove the two ' it says the location is http://localhost/webs/getoutside.php?id=".15. Do you need the full stops? If i remove them they go from the url as well. It doesnt seem to be calling getoutside.php, from what i can gather it thinks that it is a image. edit: If i change src to href i get a white box with a different icon in it -
Retrieving image from database (BLOB)? Just getting binary.
fredted40x replied to fredted40x's topic in PHP Coding Help
Are you able to check the insert code for me please. Im thinking it may either be that or the getoutside.php file. <form action="admin.php" method="post" enctype="multipart/form-data" > ... <input type="hidden" name="MAX_FILE_SIZE" value="2000000"> <input name="userfile" type="file" id="userfile"> ... admin.php include 'dbase.php'; //connect to database //get file information --step1 $fileName = $_FILES['userfile']['name']; $tmpName = $_FILES['userfile']['tmp_name']; $fileSize = $_FILES['userfile']['size']; //get file content -- step1 $fp = fopen($tmpName, 'r'); $content = fread($fp, $fileSize); $content = addslashes($content); fclose($fp); $query = "INSERT INTO apartment VALUES(NULL,...,'$content')"; mysql_query($query) -
Retrieving image from database (BLOB)? Just getting binary.
fredted40x replied to fredted40x's topic in PHP Coding Help
Ok, understand now thanks. Adding the / to make it echo "<img src=getoutside.php?id='\".$r['apartmentId']. \" '>"; gives me a unexpected T_ENCAPSED_AND_WHITESPACE error. without the \'s it now produces just a white image with an x in. -
Retrieving image from database (BLOB)? Just getting binary.
fredted40x replied to fredted40x's topic in PHP Coding Help
can you explain please? Dont think i've used them before. Heres the code to add the image if it helps. //get file information --step1 $fileName = $_FILES['userfile']['name']; $tmpName = $_FILES['userfile']['tmp_name']; $fileSize = $_FILES['userfile']['size']; //get file content -- step1 $fp = fopen($tmpName, 'r'); $content = fread($fp, $fileSize); $content = addslashes($content); fclose($fp); -
Hi, I have managed to get the code working to store a .jpg file in the database under the longblob type. Now all i have left to do is to retrieve that image and display it. So far i have this: list.php while($r = mysql_fetch_array($sql)) { //for each record ... echo " <img src= getoutside.php?id='".$r[apartmentId]. " '> "; getoutside.php <?php header("Content-type: image/jpg"); // act as a jpg file to browser $nId = $_GET['id']; include 'dbase.php'; //connect to database $sqlo = "SELECT outside FROM apartment WHERE apartmentId = $nId"; $oResult = mysql_query($sqlo); $oRow = mysql_fetch_array($oResult); $sJpg = $oRow["outside"]; echo $sJpg; ?> The result from this is a box with a red cross in it. Can anyone find a problem with this code please? Thanks
-
Would it be down to file permissions? I have just craated a test page with only the code from that link. Im not getting any errors when it submits, it just refreshes the page and doesnt upload the file. Curently im using xampp. Update: SIgnore this please, it now works on the test page.
-
Thanks for your reply. It looks similar to one i've tried before. I found that when i add the code enctype="multipart/form-data" It no longer submits to the database. Would that be because it also has text inputs in the form as well?
-
Hi, I have a basic form that lets people enter details <form action="welcome.php" method="post"> Name: <input type="text" name="fname" /> Second name: <input type="text" name="sname" /> <input type="submit" /> </form> And the standard insert in sql command. Im now looking to add a image uplad field the the same form. I have tried several methods off the internet but i cant get any to work. I would like the form to upload the image into the directory '../images' and then save the path to the file in the database, e.g. 'images/picture.jpg'. Can anyone point me in the right direction please. Im guessing i will have to use the file input type but i cant get any of it to work. Thanks
-
Hi, I have a form that allows a user to enter details and also to upload a image. The form works great and inserts into the database if i dont include the file input. What i would like happen is: The user enters details and selects a file The file then gets uploaded to ../images and the path is then written to bedroom1 variable The addresses and the bedroom1 variable that now holds the uploaded file path e.g. images/test.jpg is written to the database Form <form action="admin.php" method="POST"> <table> <tr><td> Address 1: </td><td> <input type="text" name="address1" id="address1" onfocus="selected(this)" onblur="notselected(this)"> </td><td> <div id="dynamicText1"> </div> </td></tr> <tr><td> Address 2: </td><td> <input type="text" name="address2" id="address2" onfocus="selected(this)" onblur="notselected(this)"> </td><td> <div id="dynamicText1"> </div> </td></tr> <tr><td> County: </td><td> <input type="text" name="county" id="county" onfocus="selected(this)" onblur="notselected(this)"> </td><td> <div id="dynamicText1"> </div> </td></tr> <tr><td> Bedroom 1: </td><td> <input type="file" name="bedroom1" id="bedroom1" input name="uploadedfile"> </td><td> <div id="dynamicText1"> </div> </td></tr> <tr><td> <input type="submit" name="submitaddapartment" value="Add" id="registerbutton"> </td></tr> </table </form> And the php code to add it to the database <?php //get variables $submitaddapartment = $_POST['submitaddapartment']; $address1 = strip_tags($_POST['address1']); $address2 = strip_tags($_POST['address2']); $county = strip_tags($_POST['county']); $bedroom1 = strip_tags($_POST['bedroom1']); if ($submitaddapartment) //if submit button was pressed { if ($address1&&$address2&&$county&&$bedroom1&&) //if fields arn't blank { include 'dbase.php'; //connect to database if ((($_FILES["bedroom1"]["type"] == "image/gif") || ($_FILES["bedroom1"]["type"] == "image/jpg") || ($_FILES["bedroom1"]["type"] == "image/pjpeg")) && ($_FILES["bedroom1"]["size"] < 20000000)) { if ($_FILES["bedroom1"]["error"] > 0) { echo "Return Code: " . $_FILES["bedroom1"]["error"] . "<br />"; } else { echo "Upload: " . $_FILES["bedroom1"]["name"] . "<br />"; echo "Type: " . $_FILES["bedroom1"]["type"] . "<br />"; echo "Size: " . ($_FILES["bedroom1"]["size"] / 1024) . " Kb<br />"; echo "Temp file: " . $_FILES["bedroom1"]["tmp_name"] . "<br />"; if (file_exists("../images/" . $_FILES["bedroom1"]["name"])) { echo $_FILES["bedroom1"]["name"] . " already exists. "; } else { move_uploaded_file($_FILES["bedroom1"]["tmp_name"], "/" . $_FILES["bedroom1"]["name"]); echo "Stored in: " . "../images/" . $_FILES["bedroom1"]["name"]; $bedroom1=".'images/.' $_FILES["bedroom1"]["name"]"; } } } else { echo "Invalid file"; } mysql_query ("INSERT INTO user VALUES(NULL,'$address1','$address2','$county','$bedroom1')"); } else { } } ?> Any help would be greatly appreciated. Thanks Fred
-
Thats it! Thanks sunfighter.
-
Hi, Just working on my university project, have quickly knocked up a login and register function but im now trying to create a drop down login box like twitter. It has to be written code and jquery cant be used. Is javascript the language i need? If it is can anyone point me to somewhere that could help. Thanks Fred
-
The problem is i have only done one unit on php and java at uni so have a very basic knowledge of these. I would like a calendar that shows dates that have been booked and the date that haven't been book to show as a different colour and be clickable to a email form. Basically almost exactly like that calendar.
-
Hi, As a part of my university course final year project i have to create a room reservation system. I have found this http://www.phpjabbers.com/availability-booking-calendar/index.php Which looks perfect but i cant use that as i have to code it myself. Does anyone know of a guide that will help me build something similar? Thanks in advance
-
Hi, Im trying to create a really simple password protected page that is fairly secure but when the user doesnt enter a password the wrong error is displayed. Can anyone see a problem? Also could someone please check that im properly compairing the hash password of 2135fa0dd7fb99d167b420b7ff34ec98 with what the user entered when its hashed? login.php <?php session_start(); ?> <?php $submit = $_POST['submit']; $password = md5($_POST['password']); if ($submit) { if ($password) { if ($password == '2135fa0dd7fb99d167b420b7ff34ec98') { $_SESSION['user'] = logged; header('Location: page.php'); } else { header('Location: index.php?id=1'); } } else { header('Location: index.php?id=2'); } } else { header('Location: index.php?id=1'); } ?> index.php <?php $id=$_REQUEST['id']; ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html lang="EN" dir="ltr" xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="content-type" content="text/xml; charset=utf-8" /> <title>Keys</title> <link rel = "stylesheet" type = "text/css" href = "css/layout.css" /> </head> <body> <div id="header"> <h1>Keys</h1> </div> <div id="secondheader"> </div> <div id="main"> <form method="POST" action="login.php"> Password: <input type="password" name="password" onfocus="selected(this)" onblur="notselected(this)"> <input type="submit" name="submit" value="Login"> </form> <br/> <?php if ($id==1) { echo "Invalid password. Please try again"; } elseif ($id==2) { echo "Please enter a password"; } ?> </div> <div id="footer"> </div> <div id="left"> </div> </body> </html> Thanks in advance.