This is my code <html> <body> <form action="uploading.php" method="post" enctype="multipart/form-data"> <table width="350" border="0" cellpadding="1" cellspacing="1" class="box"> <tr> <td width="246"> <input type="hidden" name="MAX_FILE_SIZE" value="2000000"> <input name="userfile" type="file" id="userfile"> </td> <td width="80"><input name="upload" type="submit" class="box" id="upload" value=" Upload "></td> </tr> </table> </form> </body> </html> <?php if(isset($_POST['upload']) && $_FILES['userfile']['size'] > 0) $con=mysql_connect("localhost" ,"root" ,""); mysql_select_db("rafi"); { $fileName = $_FILES['userfile']['name']; $tmpName = $_FILES['userfile']['tmp_name']; $fileSize = $_FILES['userfile']['size']; $fileType = $_FILES['userfile']['type']; $fp = fopen($tmpName, 'r'); $content = fread($fp, filesize($tmpName)); $content = addslashes($content); fclose($fp); if(!get_magic_quotes_gpc()) { $fileName = addslashes($fileName); } $query = "INSERT INTO upload (name, size, type, content ) ". "VALUES ('$fileName', '$fileSize', '$fileType', '$content')"; mysql_query($query) or die('Error, query failed'); $blah=mysql_query("Select * FROM upload"); while($row=mysql_fetch_assoc($blah)) echo $row['name']; } ?> when i upload any pic it did'nt show ? plz help me out!
assuming that your upload script is working and you see the images in your upload directory [check] then the <image> path's your problem
data base is not used to store binary content , use move_uploaded_files($src,$destination); give $destination a unique name by using $serverName = uniqid(); get the extension of file $ext = end(explode($filename,'.'); in the database save the extension , filename , the unique file name , and mime type.
use this code instaed: if(!get_magic_quotes_gpc()) { $fileName = addslashes(file_get_contents($Userfile)); } $query = "INSERT INTO upload (name, size, type, content ) ". "VALUES ('$fileName', '$fileSize', '$fileType', '$content')"; mysql_query($query) mysql_close(); $query="Select * FROM upload"; $blah=mysql_query($query) while( list(*)=mysql_fetch_array($blah)) echo "fileName"; } ?> PHP:
<html> <body> <form action="uploading.php" method="post" enctype="multipart/form-data"> <table width="350" border="0" cellpadding="1" cellspacing="1" class="box"> <tr> <td width="246"> <input type="hidden" name="MAX_FILE_SIZE" value="2000000"> <input name="userfile" type="file" id="userfile"> </td> <td width="80"><input name="upload" type="submit" class="box" id="upload" value=" Upload "></td> </tr> </table> </form> </body> </html> <?php if(isset($_POST['upload']) && $_FILES['userfile']['size'] > 0) $con=mysql_connect("localhost" ,"root" ,""); mysql_select_db("rafi"); { $fileName = $_FILES['userfile']['name']; $tmpName = $_FILES['userfile']['tmp_name']; $fileSize = $_FILES['userfile']['size']; $fileType = $_FILES['userfile']['type']; if(!get_magic_quotes_gpc()) { $fileName = addslashes(file_get_contents($userfile)); } $query = "INSERT INTO upload (name, size, type, content ) "."VALUES ('$fileName', '$fileSize', '$fileType', '$content')"; mysql_query($query) mysql_close($con); $query=("Select * FROM upload"); $blah=mysql_query($query) while(list(*)=mysql_fetch_array($blah)) echo "FileName"; ?> not workin
Just use this code below: <?php $maxfilesize = 2000000; if(isset($_POST['upload']) && $_FILES['userfile']['error'] === UPLOAD_ERR_OK && $_FILES['userfile']['size'] <= $maxfilesize) { $con = mysql_connect("localhost", "root", "") or die(mysql_error()); mysql_select_db("rafi", $con) or die(mysql_error()); $fileName = mysql_real_escape_string($_FILES['userfile']['name'], $con); $tmpName = mysql_real_escape_string($_FILES['userfile']['tmp_name'], $con); $fileSize = mysql_real_escape_string($_FILES['userfile']['size'], $con); $fileType = mysql_real_escape_string($_FILES['userfile']['type'], $con); $content = mysql_real_escape_string(file_get_contents($_FILES['userfile']['tmp_name']), $con); $query = "INSERT INTO upload (name, size, type, content ) VALUES ('$fileName', '$fileSize', '$fileType', '$content')"; mysql_query($query) or die('Error, query failed:' . mysql_error()); echo "<br>File $fileName uploaded<br>"; } ?> <form method="post" action="uploading.php" enctype="multipart/form-data"> <table width="350" border="0" cellpadding="1" cellspacing="1" class="box"> <tr> <td width="246"> <input type="hidden" name="MAX_FILE_SIZE" value="<?php echo $maxfilesize; ?>"> <input name="userfile" type="file" id="userfile"> </td> <td width="80"><input name="upload" type="submit" class="box" id="upload" value=" Upload "></td> </tr> </table> </form> PHP: