Recommend this page to a friend! |
PHP Sweet PDO | > | All threads | > | HELP!!!!! | > | (Un) Subscribe thread alerts |
|
![]() Hi i have this script that allows me to upload jpg or gif files onto mysql database , but, i couldn`t get my script right to show the uploaded photos on the browser. So, please i would want someone to tell me what is wrong we my output script below and probably correct it for me. Thanks John Mbachu johnmbachu@yahoo.com +2348021171733. MY WELL WORKING CODE. (image_upload.php) <HTML> <HEAD><TITLE>Upload Page</TITLE> <META http-equiv=Content-Type content="text/html; charset=iso-8859-1"> </HEAD> <BODY> <form name="form" method="post" ENCTYPE="multipart/form-data" action="image_upload.php"> <table> <tr> <td>Name: <input type="text" name="name"></td> </tr> <tr> <td > Upload image: <input type="file" name="uploadfile"> </td> </tr> <tr> <td><input name="submit" value="Upload" type="submit"> </td> </tr> </table> </form> <a href="image_get.php">See all files</a> </BODY> </HTML> <?php $host="localhost"; $user="root"; $pass="kingpin"; $db="mms_database"; $con=mysql_connect($host,$user,$pass); mysql_select_db($db); $submit = $_REQUEST['submit']; if(isset($_REQUEST['submit'])) { $imgtype=$_FILES['uploadfile']['type']; $name = addslashes(strip_tags($_REQUEST['name'])); if (!$name || !$imgtype) { echo "Please fill out all fields."; }else{ if($imgtype=="image/jpeg" || $imgtype=="image/jpg" || $imgtype=="image/pjpeg" || $imgtype=="image/gif" || $imgtype=="image/x-png" || $imgtype=="image/bmp") { $image=$_FILES['uploadfile']['tmp_name']; $fp = fopen($image, 'r'); $content = fread($fp, filesize($image)); $content = addslashes($content); fclose($fp); $result = mysql_num_rows(mysql_query("SELECT * FROM gina WHERE name='$name'")); if($result == 1) { echo '<h1>ERROR!</h1>The filename you have chosen already exists!'; } else { $sql="insert into gina (name,image,created) values ('$name','$content',NOW())"; $res=mysql_query($sql) or die (mysql_error()); echo "Upload successful!"; } } else { echo " Sorry may be your file is not a jpg or gif file! "; } } } /* CREATE TABLE `mms_database`.`gina` ( `id` INT NOT NULL AUTO_INCREMENT , `name` VARCHAR( 255 ) NOT NULL , `image` MEDIUMBLOB NOT NULL , PRIMARY KEY ( `id` ) ) ENGINE = MYISAM */ ?> BELOW IS MY TROUBLING SCRIPT(image_get.php) <?php $host="localhost"; $user="root"; $pass="kingpin"; $db="mms_database"; // Connects to your Database mysql_connect("localhost", "root", "kingpin") or die(mysql_error()); $con = (mysql_select_db("mms_database") or die(mysql_error())); // Query for a list of all existing files $sql = "SELECT * FROM gina WHERE id='$id'"; $result = "$con(mysql_query($sql))"; $count = "$con(mysql_num_rows($result))"; // Check if it was successfull if($count) { // Make sure there are some files in there if($count == 0) { echo '<p>There are no files in the database</p>'; } else { // Print the top of a table echo '<table width="100%"> <tr> <td><b>Name</b></td> <td><b>Image</b></td> <td><b>Created</b></td> </tr>'; while($count = (mysql_fetch_array($result)) { echo " <tr> <td>{$count['name']}</td> <td>{$count['image']}</td> <td>{$count['created']}</td> <td><a href='get_file.php?id={$row['id']}'>Download</a></td> </tr>"; } echo '</table>'; } } else { echo 'Error! SQL query failed:'; } ?> |
info at phpclasses dot org
.