contra10
-
Posts
402 -
Joined
-
Last visited
Never
Posts posted by contra10
-
-
-
i guess it is vague, but im just trying to make it as simple as possible
-
i did it and i'm still getting the same binary data....
do u remember if the other issue was solved?
maybe im inputting the information wrong?
-
ok i have this code that for some reason only inputs the data but can't read the image file
<?php mysql_connect("localhost", "root", "") or die(mysql_error()); mysql_select_db("registration") or die(mysql_error()); if(isset($_POST['upload']) && $_FILES['userfile']['size'] > 0) { $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 = mysql_real_escape_string($content); fclose($fp); if(!get_magic_quotes_gpc()) { $fileName = mysql_real_escape_string($fileName); } $query = "INSERT INTO image (name, size, type, content ) ". "VALUES ('$fileName', '$fileSize', '$fileType', '$content')"; mysql_query($query) or die('Error, query failed'); echo "<br>File $fileName uploaded<br>"; } ?> </body> </html> <table border="1" cellpadding="10"> <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" 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> </form> </table> <?php mysql_connect("localhost", "root", "") or die(mysql_error()); mysql_select_db("registration") or die(mysql_error()); $query = "SELECT * FROM image WHERE id= '1'"; $result = mysql_query($query); $row = mysql_fetch_assoc($result); header("Content-type: image/gif"); echo($row['content']); ?>
instead i get
Ic„V^‰e–+QÙ$—]ò䥌c~ &‰>žYáUj¢d›•iœÒ¹$œíÙˆçŒ5äçŸ'¥¸'Zcý©PŒvê÷’Ÿi9(D¾æ£³æ(¥·å馂NÊ©„—~ ÒŽ‰Iª¨kþX)ª‡ÎD\©ŠÿÙ*¬ö9V¬¶Šd¦´Öºå½úåœPæªë°iUi,±:zÓ²Ç6;U°ÂéµÕ6È(´ÑZË-mÞ~›)‘âv‹l¹ã†‹.³ê®›l»îš)m¼•‰-öÒ[¯˜ú²ûk¿rÞë_Àý^K§Àå",®Âß2ÌÃÐB¼¬ÄÆRœ«Å¬bŒªÆ¬£Çl‚œ¦ÈäVh(ÉàŽº$DZºé/ÊwÆy+Ìûâ)Í//Ų‹áí\ãs>÷émA9tQÛ⌠G+íôÓPG-õÔTWmõÕXgõÖ\wíõ×`‡-öØd—möÙh§öÚl·íöÛpÇ-÷Üt×m÷Ýxç÷Þ|÷Gí÷߀.øà„nøáˆ'®øâŒ7îøãG.ùä”Wnùå˜g®ùæœwîùç ‡.ú褗nú騧®úꬷîúë°Ç.ûìR;>GIF89aïü÷€€€€€€€€€€€€ÀÀÀÿÿÿÿÿÿÿÿÿÿÿÿ3f™Ìÿ3333f3™3Ì3ÿff3fff™fÌfÿ™™3™f™™™Ì™ÿÌÌ3ÌfÌ™ÌÌÌÿÿÿ3ÿfÿ™ÿÌÿÿ3333f3™3Ì3ÿ3333333f33™33Ì33ÿ3f3f33ff3f™3fÌ3fÿ3™3™33™f3™™3™Ì3™ÿ3Ì3Ì33Ìf3Ì™3ÌÌ3Ìÿ3ÿ3ÿ33ÿf3ÿ™3ÿÌ3ÿÿff3fff™fÌfÿf3f33f3ff3™f3Ìf3ÿffff3fffff™ffÌffÿf™f™3f™ff™™f™Ìf™ÿfÌfÌ3fÌffÌ™fÌÌfÌÿfÿfÿ3fÿffÿ™fÿÌfÿÿ™™3™f™™™Ì™ÿ™3™33™3f™3™™3Ì™3ÿ™f™f3™ff™f™™fÌ™fÿ™™™™3™™f™™™™™Ì™™ÿ™Ì™Ì3™Ìf™Ì™™ÌÌ™Ìÿ™ÿ™ÿ3™ÿf™ÿ™™ÿÌ™ÿÿÌÌ3ÌfÌ™ÌÌÌÿÌ3Ì33Ì3fÌ3™Ì3ÌÌ3ÿÌfÌf3ÌffÌf™ÌfÌÌfÿ̙̙3Ì™fÌ™™Ì™ÌÌ™ÿÌÌÌÌ3ÌÌfÌÌ™ÌÌÌÌÌÿÌÿÌÿ3ÌÿfÌÿ™ÌÿÌÌÿÿÿÿ3ÿfÿ™ÿÌÿÿÿ3ÿ33ÿ3fÿ3™ÿ3Ìÿ3ÿÿfÿf3ÿffÿf™ÿfÌÿfÿÿ™ÿ™3ÿ™fÿ™™ÿ™Ìÿ™ÿÿÌÿÌ3ÿÌfÿÌ™ÿÌÌÿÌÿÿÿÿÿ3ÿÿfÿÿ™ÿÿÌÿÿÿ!ù,ïüÿÿ H° Áƒ*\ˆÅ‡#JœH±¢Å‹3jœØp£Ç CŠI’bÇ’(Sª\É2¤C‡-cÊœISåËš8sêÜÉðLž@ƒ µ)ðçУH“V„iT©Ó§P}JµêP¦V³j¥ù³éÖ¯`]ô¶¬Y“cϪ]Ñ(Y¶p×6}·nعvóªÅ«·/X¯tý FJ6ðàÃ@ #^œT1ãÇACžœóaʘIZÎÌ™%ÝËCcü,º´HÒ¦SoDºõÒž®c·…-»vBà m«¾œ[·iн}wÎ\xæÞÅOF®\vñäÍ?Þ:9tê}¡_ÇžW;wÑ×·ÿg»]üø½ÍŸ¿«Qýú¯êݿϾtòíG•Ÿ_¿Sþþe'V€võ×Bx ‚;-¸ ƒ•i!z#=8¡LZxaKj¸aJzøaI"Š8âiDH•‰R©‹,º˜‡2*c‹5u#Ž9F†a rdbBÙ`M;YP’1©äT89©¤”<>Ic„V^‰e–+QÙ$—]ò䥌c~ &‰>žYáUj¢d›•iœÒ¹$œíÙˆçŒ5äçŸ'¥¸'Zcý©PŒvê÷’Ÿi9(D¾æ£³æ(¥·å馂NÊ©„—~ ÒŽ‰Iª¨kþX)ª‡ÎD\©ŠÿÙ*¬ö9V¬¶Šd¦´Öºå½úåœPæªë°iUi,±:zÓ²Ç6;U°ÂéµÕ6È(´ÑZË-mÞ~›)‘âv‹l¹ã†‹.³ê®›l»îš)m¼•‰-öÒ[¯˜ú²ûk¿rÞë_Àý^K§Àå",®Âß2ÌÃÐB¼¬ÄÆRœ«Å¬bŒªÆ¬£Çl‚œ¦ÈäVh(ÉàŽº$DZºé/ÊwÆy+Ìûâ)Í//Ų‹áí\ãs>÷émA9tQÛ⌠G+íôÓPG-õÔTWmõÕXgõÖ\wíõ×`‡-öØd—möÙh§öÚl·íöÛpÇ-÷Üt×m÷Ýxç÷Þ|÷Gí÷߀.øà„nøáˆ'®øâŒ7îøãG.ùä”Wnùå˜g®ùæœwîùç ‡.ú褗nú騧®úꬷîúë°Ç.ûìR;
if u can please, please please tell me how to solve this or another way i can upload and view...I've tried all of the resource websites i can find and i get nowhere
-
well thanks for trying, ill jus have to figure out another way
-
i get
Error, query failed! You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '-=-157:::#+?D?8C49:7ÿÛ' at line 1
sry if im bothering u
-
i did this
<?php mysql_connect("localhost", "root", "") or die(mysql_error()); mysql_select_db("registration") or die(mysql_error()); if(isset($_POST['upload']) && $_FILES['userfile']['size'] > 0) { $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 = mysql_real_escape_string($content); fclose($fp); if(!get_magic_quotes_gpc()) { $fileName = mysql_real_escape_string($fileName); } $query = "INSERT INTO image (name, size, type, content ) ". "VALUES ('$fileName', '$fileSize', '$fileType', '$content')"; mysql_query($query) or die('Error, query failed'); echo "<br>File $fileName uploaded<br>"; } ?> </body> </html> <table border="1" cellpadding="10"> <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" 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> </form> </table> <?php $query = "SELECT content FROM image WHERE id= '1'"; $result = mysql_query($query); $row = mysql_fetch_assoc($result); header("Content-type: image/pjpeg"); echo($row['content']); ?>
and got the same thing as before
and i also did this
<?php mysql_connect("localhost", "root", "") or die(mysql_error()); mysql_select_db("registration") or die(mysql_error()); if(isset($_POST['upload']) && $_FILES['userfile']['size'] > 0) { $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)); fclose($fp); $query = "INSERT INTO image (name, size, type, content ) ". "VALUES ('$fileName', '$fileSize', '$fileType', '$content')"; mysql_query($query) or die('Error, query failed'); echo "<br>File $fileName uploaded<br>"; } ?> </body> </html> <table border="1" cellpadding="10"> <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" 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> </form> </table> <?php $query = "SELECT content FROM image WHERE id= '1'"; $result = mysql_query($query); $row = mysql_fetch_assoc($result); header("Content-type: image/pjpeg"); echo($row['content']); ?>
and got "query error".
-
NVM id did not take up 2 fields
-
yes u were definatly right with the content...
i have
<?php $query = "SELECT content FROM image WHERE id= '1'"; $result = mysql_query($query); $row = mysql_fetch_assoc($result); header("Content-type: image/jpeg"); echo($row['content']); ?>
i also tried
<?php $query = "SELECT content FROM image WHERE id= '1'"; $result = mysql_query($query); $row = mysql_fetch_assoc($result); header("Content-type: image/pjpeg"); echo($row['content']); ?>
since it was pjpeg in the database,
i still get
ÿØÿàJFIFÿÛC "" $(4,$&1'-=-157:::#+?D?8C49:7ÿÛC 7%%77777777777777777777777777777777777777777777777777ÿÀ00"ÿÄÿÄ.!1AQq"#B¡±$2b‘ÿÄÿÄ!1QÿÚ ?ÎQ‘/Ú¼‰`(ál‡Gî#oZÓý-%¬KYdU'ÎŽ é ðEj¦W$û“Ú$[#¼‘ÝËwb×üVwdo’fظ0Á4Ÿ Ø¿ÕÅ-âùûzÜsC.âºáí¤µ ø§±ÜФ;SV;Ué]ˆˆæÛPTíEFRlÜwªJJ1m’¾Y¦tÿWá±ø8g›1Ž UBK^±ä7í\‡TæSf™¬’sd…CôžçÔÛíUM6Ål$†‘4U¨¾ö=»ÿ´¸Tðc䑵…ïYê#ÓwdFvØìE‘ÜÐœÔÜB«Æîƒâ[ŸQTÒâ §¾6GPºqõx>Âœ%ÒÊOª?ˆ§Jß oü«*̯ÒiŽÈŸâ€wX½#ÊéñFnFà_jŽ¯hÁ;©µÍ1Ée ƒ¸¥AeŒ¿'b-\ô„«2·*H«¬,ÀéÔqÈÛš£ÅÔÌ/õ·æŠãK5±nÿÙ
i really don't know y this can't work for me, everything your doing is right and i thought it was correct
here's my whole code at the moment
<?php mysql_connect("localhost", "root", "") or die(mysql_error()); mysql_select_db("registration") or die(mysql_error()); if(isset($_POST['upload']) && $_FILES['userfile']['size'] > 0) { $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 image (name, size, type, content ) ". "VALUES ('$fileName', '$fileSize', '$fileType', '$content')"; mysql_query($query) or die('Error, query failed'); echo "<br>File $fileName uploaded<br>"; } ?> </body> </html> <table border="1" cellpadding="10"> <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" 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> </form> </table> <?php $query = "SELECT content FROM image WHERE id= '1'"; $result = mysql_query($query); $row = mysql_fetch_assoc($result); header("Content-type: image/pjpeg"); echo($row['content']); ?> </tr> </form> </table> <body> </html>
files can go in but they can't come out....
i don't know if this helps but i uploaded 2 images and already my id count is up to 4 i think each image is taking up 2 id fields
-
the code before the switch to this one was workin well but i could not view the files, a pop-up came on my screen saying that i had to downloaod file
-
just to note i did that prviously, didn't work...but im using the resource website that you found and on page 7 it basically says this
<?php // the upload function function upload(){ if(is_uploaded_file($_FILES['userfile']['tmp_name'])) { // check the file is less than the maximum file size if($_FILES['userfile']['size'] < $maxsize) { // prepare the image for insertion $imgData =addslashes (file_get_contents($_FILES['userfile']['tmp_name'])); // $imgData = addslashes($_FILES['userfile']); // get the image info.. $size = getimagesize($_FILES['userfile']['tmp_name']); // put the image in the db... mysql_connect("localhost", "root", "") or die(mysql_error()); mysql_select_db("registration") or die(mysql_error()); // our sql query $sql = "INSERT INTO testblob ( image_id , image_type ,image, image_size, image_name) VALUES ('', '{$size['mime']}', '{$imgData}', '{$size[3]}', '{$_FILES['userfile']['name']}')"; // insert the image if(!mysql_query($sql)) { echo 'Unable to upload file'; } } } else { // if the file is not less than the maximum allowed, print an error echo '<div>File exceeds the Maximum File limit</div> <div>Maximum File limit is '.$maxsize.'</div> <div>File '.$_FILES['userfile']['name'].' is '.$_FILES['userfile']['size'].' bytes</div> <hr />'; } } ?>
with the exception that i put my databse connection in there... when i submit the data does not enter the table and i get this mesage
File exceeds the Maximum File limit Maximum File limit is File Array is Array bytes -------------------------------------------------------------------------------- Thank you for submitting
any ideas?
-
thank u it looks pretty useful!
-
<?php $query = "SELECT content FROM image WHERE id= '1'"; $result = mysql_query($query); $row = mysql_fetch_assoc($result); // We'll be outputting a jpeg header("Content-type: img/pjpeg"); // this needs to be changed to the actual type of the image, png, gif, jpeg etc echo $row['content']; ?>
-
oh ok, i did that and i changed it around and when i click on the link to the page a get a window that asks me to save the file index.php i guess its because the image did upload to the page but i would have to download it?
-
am i srtof on the right track
<?php if(is_numeric($_GET['id'])){ $id = $_GET['id']; $insert1= "SELECT * FROM users WHERE id = '$id'"; $idnu = mysql_query($insert1) or die(mysql_error()); while ($idn = mysql_fetch_assoc($idnu)) { $idnumb= "{$idn['id']}"; } } header("Location: http://localhost/photoupload/index.php?userphotoid=$idnumb"); $query = "SELECT content FROM image WHERE id= '1'"; $result = mysql_query($query); while($row = mysql_fetch_assoc($result)) { $ii = "{$row['content']} <br>"; echo($ii); } echo($ii); ?>
-
the image file is in the database but it comes out as binary, how do i convert it back?
-
hey i want to read an image file i uploaded into database
<?php $query = "SELECT content FROM image WHERE id= '1'"; $result = mysql_query($query); while($row = mysql_fetch_assoc($result)) { $ii = "{$row['content']} <br>"; echo($ii); } echo($ii); ?>
how di i see the image
-
hould i get rid of both slashes, back/front, i guess my question is how do i make them connect
-
if(!move_uploaded_file ($upfile,$new_fullpath)){ die("copy failed.");
for some reason it still doesnt' work i get
Warning: move_uploaded_file(C:\wamp\www\imagealbum\/article/world2png) [function.move-uploaded-file]: failed to open stream: No such file or directory in C:\wamp\www\image_process.php on line 70 Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move 'C:\wamp\tmp\phpCA.tmp' to 'C:\wamp\www\imagealbum\/article/world2png' in C:\wamp\www\image_process.php on line 70 copy failed.
}
-
is my file not being found? could it be the file path?
-
thxs that solved the first part but i still get this error
Warning: copy(C:\wamp\www\imagealbum\/article/n28289389880_7562jpg) [function.copy]: failed to open stream: No such file or directory in C:\wamp\www\image_process.php on line 70 copy failed.
the directory or file does exists
-
hey im trying to make this code work for an image upload
<?php /*configuration */ $root= "C:\\wamp\\www\\imagealbum\\"; $urlroot = "http://localhost/images/"; $max_width= 420; $max_height = 600; $overwrite_images = false; $target_dirs = array("article", "banners"); if(!function_exists(getimagesize)){ die("getimagesize() required."); } $location = strval($_POST['location']); $newname = strval($_POST['newname']); $upfile = $_FILES['upfile']['tmp_name']; $upfile_name = $_FILES['upfile']['name']; if($newname){ $newname= preg_replace('/[^A-Za-z0-9_.-]/', '', $newname); }else{ $newname = preg_replace('/[^A-Za-z0-9_.-]/', '',$upfile_name); } if (!in_array($location, $target_dirs)){ die("invalid target directory."); }else{ $urlroot .="/location"; } if (!upfile){ die("no file for upload. "); } $file_types = array( "image/jpeg" => "jpg", "image/pjpeg" =>"jpg", "image/gif" => "gif", "image/png" => "png", ); $width = null; $height = null; $img_info = getimagesize($upfile); $upfile_type = $img_info["mime"]; list ($width, $height, $t, $attr) = $img_info; if (!$file_types[$upfile_type]){ die("Image must be in JPEG, GIF, or PNG format"); }else{ $file_suffix = $file_types[$upfile_type]; } if($width > $max_width || $height > $max_height){ die ("size $width x $height exceeds maximum $max_width x $max_height."); } $newname = preg_replace('/\.(jpe?g|gif|png)$/i', ""); $newname .= $file_suffix; $new_fullpath = "$root/$location/$newname"; if((!overwrite_images) && file_exists($new_fullpath)){ die("file exists; will not overwrite."); } if(!copy($upfile,$new_fullpath)){ die("copy failed."); } $image_url = "$urlroot/$newname"; print "HTML for image:</strong><br><textarea cols=\"80\" rows\"4\">"; print "<img src\"image_url\" $attr alt=\"$upfile_name\" border=\"0\"/>"; print "</textarea><br>"; print '<a href="http://localhost/photoupload/"> Upload another image></a>'; ?>
instead i get these errors
Warning: Wrong parameter count for preg_replace() in C:\wamp\www\image_process.php on line 62 Warning: copy(file:///C|/wamp/www/images//article/jpg) [function.copy]: failed to open stream: Invalid argument in C:\wamp\www\image_process.php on line 70 copy failed.
-
ohhh i didn't know that thank you
-
im using notepad ++ and
$root= "C:\wamp\www\images\"; $urlroot = "http[color=green]://localhost/images/";[/color]
it looks like that so the rest of my code won't work
[SOLVED] need a way to upload and view images inserted to database
in PHP Coding Help
Posted
longblob