Databases :: MySql :: Adding jpg or gif images to a mysql search output |
|||
| By: dcatkin |
Date: 03/11/2004 00:00:00 |
Points: 250 | Status: Answered Quality : Excellent |
|
I need to add images of parts or cars in our database so people know what their getting, and I would like some help on this question if anybody can. You can go to this in the search area enter engine, cmaaro, 1978 for the year <A HREF="http://hp-car.com/parts/index.php">http://hp-car.com/parts/index.php</A> David C. Atkin |
|||
| By: VGR | Date: 04/11/2004 04:23:00 | Type : Comment |
|
| yes. Store filenames (or references of) in the DB This way seeing an order's contents will result from a simple image src= name generation or a simple implicit JOIN on the two tables. for instance, in your case you return those columns : Parts Year Model Price Description Name Address Email Phone URL Well, just accomodate the TABLE layout for the display of an image tag (IMG) of fixed size (either height or width, take 100 for example), then store in the DB a reference of images or directly the filename (example : camaroEngine.jpg ). Then get that image and store it in a subdirectory, for example "./images" or "./images/motors" if you want to split images per parts type) Then after reading your records from the "parts" DB, where the imagename column goes into $imagename, simply display in the table <IMG SRC='images/$imagename' width=100> and you're done with it. |
|||
| By: dcatkin | Date: 04/11/2004 23:47:00 | Type : Comment |
|
| I haven't got it solved yet, I can't seem to get it to read the directory, and also the people with the cars need to be able to upload to just use a form with a browse button and upload and image to <A HREF="http://hp-car.com/cars/images">http://hp-car.com/cars/images</A>. |
|||
| By: VGR | Date: 04/11/2004 23:53:00 | Type : Comment |
|
| 1) beware of safe_mode for local file access outside of $DOCUMENT_ROOT 2) uploading a file is rather simple. See in the one to three last accepted answers in PHP area |
|||
| By: dcatkin | Date: 05/11/2004 00:50:00 | Type : Comment |
|
| I can't seem to get it going, I can't get it to locate an image in the database and display it, or upload an image, here is the upload script that I'm using. <div id="Layer1" class="c5"> <div class="c3"> <table width="98%" border="0" bordercolor="#CCCCCC" bgcolor= "#00FFFF" summary="Upload"> <tr> <td height="26"> <form enctype="multipart/form-data" action="uload_cars.php" method="post"><input type="hidden" name="MAX_FILE_SIZE" value= "3000000"> Send this file: <input name="userfile" type="file"> <input name="submit" type="submit" value="Send File"> [php]<?php if ($userfile=="none") { echo "Problem: no file uploaded"; exit; } if ($userfile_size==0) { echo "Problem: Uploaded file is zero in length"; exit; } if ($userfile_type != "image/jpg"; { echo "Problem: file is not an image"; exit; } if (! is_uploaded_file($userfile)) { echo "Problem: Possible file upload attack"; exit; } $upfile = "/home/hp-car/www/cars/images/"./$upflie_images; if ( !copy($userfile, $upflie)) { echo "Problem: "Could not move file into the directory"; exit; } echo "File uploaded successfully <hr>"; $fp = fopen($ufile, "r"); $contents = fread ($fp, filesize ($upfile)); fclose ($fp); $contents = strip_tags($contents); $fp = fopen ($upfile, "w"); fwrite ($fp, $contents); fclose($fp); echo "Preview of uploaded file contents: <hr>"; echo "$contents"; echo " <hr>"; ?>[/php] </form> </td> </tr> </table> </div> <div class="c3"> <table width="98%" border="0" summary="Upload"> <tr> <td><strong class="c4">A picture is worth 1,000 words, upload a picture of the car you have for sale here.</strong></td> </tr> </table> |
|||
| By: Big_Red_Dog | Date: 05/11/2004 01:12:00 | Type : Comment |
|
| There is a lot of missing context here. Please post complete files |
|||
| By: dcatkin | Date: 05/11/2004 01:51:00 | Type : Comment |
|
| What is missing and I'll see if I've just misplaced it. |
|||
| By: Big_Red_Dog | Date: 05/11/2004 02:05:00 | Type : Comment |
|
| Well, you have $userfile_size, $userfile_type, yet the code where these are set is missing. It seems like two fragments are jammed together because the form is followed by the upload logic without the PHP directives to use the form on the first pass and the upload logic on the second pass through the php file. |
|||
| By: dcatkin | Date: 05/11/2004 02:31:00 | Type : Comment |
|
| Would it be entries such as this $HTTP_POST_FILES['Userfile']['temp_name'] $HTTP_POST_FILES['Userfile']['name'] $HTTP_POST_FILES['Userfile']['size'] $HTTP_POST_FILES['Userfile']['type'] |
|||
| By: Big_Red_Dog | Date: 05/11/2004 02:42:00 | Type : Comment |
|
| That's part of it, but where is the logic to use part of the PHP on form entry and the other part when uploading? |
|||
| By: dcatkin | Date: 05/11/2004 02:47:00 | Type : Comment |
|
| You mean the dynamic php code, correct ? |
|||
| By: Big_Red_Dog | Date: 05/11/2004 02:57:00 | Type : Comment |
|
| No. For this page to work, you need some logic like this: <HTML> <HEAD> ... HEAD STUFF ... </HEAD> <BODY> <?PHP if ( <condition_where_upload_form_has_not_been_filled_out> ) { ?> .... BODY STUFF... <FORM> </FORM> <?PHP } else { ... PHP code to upload form ... } ?> ... Closing BODY STUFF ... </BODY> </HTML> |
|||
| By: VGR | Date: 05/11/2004 03:28:00 | Type : Comment |
|
| RTFM <html> <head> <title>upload</title> </head> <body bgcolor="#ffffff" text="#000000" link="#0000ff" vlink="#0000ff" alink="#0000ff" topmargin="0" marginheight="0"> <?php $DEBUG=1; if ($DEBUG==1) echo "test: entering "; if (isset($_POST['submit'])) { $freeSpace=$MAX_FILE_SIZE; if ($freeSpace==0) echo "no space left "; else { if ($DEBUG==1) echo "test: good, copying file... "; $loctaille=$FUserFile_size; $realName=$FUserFile_name; if (!copy($FUserFile, "./files/$realName")) echo ("failed to copy $realName... "); else echo "file $FUserFile copied successfully. "; } // space left } // POST data received if ($DEBUG==1) echo "test: getting out to HTML "; ?> <p> </p> <FORM METHOD="POST" ACTION=<?php echo"$PHP_SELF"; ?> ENCTYPE="multipart\form-data"> <INPUT border=0 TYPE=file NAME=FUserFile> <INPUT border=0 TYPE=submit NAME=submit VALUE="Load"> <input type=hidden name=MAX_FILE_SIZE value=2000000> </form> </body> </html> |
|||
| By: dcatkin | Date: 05/11/2004 03:31:00 | Type : Comment |
|
| This is the whole 9 yards, it gaves me a 404 error now. I left a link at the bottom of the page. <?php session_start(); mysql_connect("localhost", "dcatkin", "hellfire") or die("(".mysql_errno().") Error:".mysql_error()); mysql_select_db( "cars" ) or die("(".mysql_errno().") Error:".mysql_error()); ?> <html> <head> <title>Upload</title> <meta http-equiv="Content-Type" content= "text/html; charset=iso-8859-1"> <script language="JavaScript" type="text/JavaScript"> <!-- function MM_reloadPage(init) { //reloads the window if Nav4 resized if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) { document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }} else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload(); } MM_reloadPage(true); //--> </script> <style type="text/css"> body { background-color: #0066CC; } div.c5 {position:absolute; width:587px; height:342px; z-index:1; left: 220px; top: 143px;} strong.c4 {font-size: 120%} div.c3 {text-align: center} a.c2 {font-size: 144%} td.c1 {font-size: 144%} </style> </head> <body> <div class="c3"> <table width="800" border="0" summary="Upload"> <tr> <td width="677" height="688" align="left" valign="top" bgcolor= "#00FFFF"> <table width="100%" border="0" summary="Upload"> <tr> <td height="682" valign="top" bgcolor="#00CCFF"> <table width="100%" border="0" bgcolor="#0033CC" summary="Upload"> <tr> <td height="115"><img src="images/3dtext_21393.gif" alt="Hp-Car" width="790" height="106"></td> </tr> </table> <table width="120" border="0" align="left" summary="Hp-Car"> <tr> <td width="114" height="38" align="center" bgcolor="#3300CC" class="c1"><span class="c2"><a href= "<A HREF="http://hp-car.com/index.html">http://hp-car.com/index.html</A>"><img src="buttons/home.gif" alt= "parts/buttons/home.gif" width="100" height="37" border="0"> </a></span></td> </tr> <tr> <td align="center" bgcolor="#3300CC" class="c3"><a href= "<A HREF="http://hp-car.com/parts/index.php">http://hp-car.com/parts/index.php</A>" class="c2"><img src= "buttons/parts.gif" alt="buttons/parts.gif" width="100" height= "37" border="0"></a></td> </tr> <tr> <td align="center" bgcolor="#3300CC" class="c3"><a href= "<A HREF="http://hp-car.com/info/index.html">http://hp-car.com/info/index.html</A>" class="c2"><img src= "buttons/info.gif" alt="buttons/info.gif" width="100" height="37" border="0"></a></td> </tr> <tr> <td align="center" bgcolor="#3300CC" class="c3"><a href= "<A HREF="http://hp-car.com/engine/index.html">http://hp-car.com/engine/index.html</A>" class="c2"><img src= "buttons/engine.gif" alt="buttons/engine.gif" width="100" height= "37" border="0"></a></td> </tr> <tr> <td align="center" bgcolor="#3300CC" class="c3"><a href= "<A HREF="http://hp-car.com/users/index.html">http://hp-car.com/users/index.html</A>" class="c2"><img src= "buttons/user.gif" alt="buttons/user.gif" width="100" height="37" border="0"></a></td> </tr> <tr> <td align="center" bgcolor="#3300CC" class="c3"><a href= "<A HREF="http://hp-car.com/b+p/index.html">http://hp-car.com/b+p/index.html</A>" class="c2"><img src= "buttons/body.gif" alt="buttons/body.gif" width="100" height="37" border="0"></a></td> </tr> <tr> <td align="center" bgcolor="#3300CC" class="c3"><a href= "<A HREF="http://hp-car.com/cgi-bin/chat/chat.cgi">http://hp-car.com/cgi-bin/chat/chat.cgi</A>" class="c2"><img src= "buttons/chat.gif" alt="buttons/chat.gif" width="100" height="37" border="0"></a></td> </tr> <tr> <td align="center" bgcolor="#3300CC" class="c3"><a href= "<A HREF="http://hp-car.com/forum/index.php">http://hp-car.com/forum/index.php</A>" class="c2"><img src= "buttons/forums.gif" alt="parts/buttons/forums.gif" width="100" height="33" border="0"></a></td> </tr> <tr> <td align="center" bgcolor="#3300CC" class="c3"><a href= "<A HREF="http://hp-car.com/advert/index.html">http://hp-car.com/advert/index.html</A>" class="c2"><img src= "buttons/biz.gif" alt="parts/buttons/biz.gif" width="100" height= "37" border="0"></a></td> </tr> <tr> <td align="center" bgcolor="#3300CC" class="c3"><a href= "<A HREF="http://hp-car.com/gbook/jgb.php3">http://hp-car.com/gbook/jgb.php3</A>" class="c2"><img src= "buttons/guest.gif" alt="buttons/guest.gif" width="100" height= "37" border="0"></a></td> </tr> <tr> <td height="37" align="center" bgcolor="#3300CC" class="c3"><a href="<A HREF="http://hp-car.com/links/index.php">http://hp-car.com/links/index.php</A>" class="c2"><img src= "buttons/links.gif" alt="parts/buttons/links.gif" width="100" height="37" border="0"></a></td> </tr> <tr> <td height="23" valign="top" bgcolor="#0000CC"> <div class="c1 c3"><a href="<A HREF="http://hp-car.com/cars/index.php">http://hp-car.com/cars/index.php</A>" class="c2"><img src="buttons/CARS.GIF" alt="Button" width="100" height="37" border="0" lowsrc="/buttons/CARS.GIF"></a></div> </td> </tr> <tr> <td height="23" valign="top" bgcolor="#0000CC"> <div class="c1 c3"><a href= "<A HREF="http://hp-car.com/cgi-bin/search/search.pl">http://hp-car.com/cgi-bin/search/search.pl</A>" target="_self" class="c2"><img src="buttons/SEARCH.GIF" alt="Button" width="100" height="37" border="0" lowsrc="/buttons/SEARCH.GIF"></a></div> </td> </tr> <tr> <td height="35" align="center" valign="top" bgcolor="#00CCFF"><a href="<A HREF="http://www.redhat.com">http://www.redhat.com</A>" class="c2"><img src= "images/poweredby.png" alt="Button" width="88" height="31" border="0"></a></td> </tr> </table> <div id="Layer1" class="c5"> <div class="c3"> <table width="98%" border="0" bordercolor="#CCCCCC" bgcolor= "#00FFFF" summary="Upload"> <tr> <td height="26"> <form enctype="multipart/form-data" action="uload_cars.php" method="post"><input type="hidden" name="MAX_FILE_SIZE" value="3000000"> Send this file: <input name="userfile" type="file"> <input name="submit" type="submit" value="Send File"> <?php if ($userfile=="none") { echo "Problem: no file uploaded"; exit; } if ($userfile_size==0) { echo "Problem: Uploaded file is zero in length"; exit; } if ($userfile_type != "image/jpg") { echo "Problem: file is not an image"; exit; } if (! is_uploaded_file($userfile)) { echo "Problem: Possible file upload attack"; exit; } $upfile = "/home/hp-car/www/cars/images/".$upflie_images; if ( !copy($userfile, $upflie)) { echo "Problem: Could not move file into the directory"; exit; } echo "File uploaded successfully <hr>"; $fp = fopen($ufile, "r"); $contents = fread ($fp, filesize ($upfile)); fclose ($fp); $contents = strip_tags($contents); $fp = fopen ($upfile, "w"); fwrite ($fp, $contents); fclose($fp); echo "Preview of uploaded file contents: <hr>"; echo "$contents"; echo " <hr>"; $DEBUG=1; if ($DEBUG==1) echo "test: entering "; if (isset($_POST['submit'])) { $freeSpace=$MAX_FILE_SIZE; if ($freeSpace==0) echo "no space left "; else { if ($DEBUG==1) echo "test: good, copying file... "; $loctaille=$FUserFile_size; $realName=$FUserFile_name; if (!copy($FUserFile, "./files/$realName")) echo ("failed to copy $realName... "); else echo "file $FUserFile copied successfully. "; } // space left } // POST data received if ($DEBUG==1) echo "test: getting out to HTML "; ?> </form> </td> </tr> </table> </div> <div class="c3"> <table width="98%" border="0" summary="Upload"> <tr> <td><strong class="c4">A picture is worth 1,000 words, upload a picture of the car you have for sale here.</strong></td> </tr> </table> </div> </div> </td> </tr> </table> </td> </tr> </table> </div> </body> </html> <A HREF="http://hp-car.com/cars/upload_cars.php">http://hp-car.com/cars/upload_cars.php</A> |
|||
| By: VGR | Date: 05/11/2004 04:27:00 | Type : Comment |
|
| a 404 error can't have to do with the PHP code 8-) you can try to : -verify that your script is named uload_cars.php because that's the one called by the (well-formed) FORM -verify that the subdirectory ./files exists, as it seems you use ./images -put the $_POST[] handling BEFORE the printout of the FORM, it would be clearer -you can redirect from the $_POST[] handling, if you don't want to display the FORM again (then put the $_POST[] handling before any HTML output statements -set $DEBUG=1 at the start BEWARE, typo here : $upfile = "/home/hp-car/www/cars/images/".$upflie_images; if ( !copy($userfile, $upflie)) upflie vs upfile BEWARE, possible typo here also : $fp = fopen($ufile, "r"); isn't this $upfile ? |
|||
| By: dcatkin | Date: 05/11/2004 05:08:00 | Type : Comment |
|
| I corrected the typeos and it fixed the 404, but it's still not uploading files. Tahnks for your help guys. |
|||
| By: VGR | Date: 05/11/2004 05:17:00 | Type : Comment |
|
| sorry, but there were so many (potential and real) typos that I've to ask you your current code 8-) |
|||
| By: dcatkin | Date: 05/11/2004 07:00:00 | Type : Comment |
|
| Heres the corrected php code : <form enctype="multipart/form-data" action="upload_cars.php" method="post"><input type="hidden" name="MAX_FILE_SIZE" value="3000000"> Send this file: <input name="userfile" type="file"> <input name="submit" type="submit" value="Send File"> <?php if ($userfile=="none") { echo "Problem: no file uploaded"; exit; } if ($userfile_size==0) { echo "Problem: Uploaded file is zero in length"; exit; } if ($userfile_type != "image/jpg") { echo "Problem: file is not an image"; exit; } if (! is_uploaded_file($userfile)) { echo "Problem: Possible file upload attack"; exit; } $upfile = "/home/hp-car/www/cars/images/".$upflie_images; if ( !copy($userfile, $upflie)) { echo "Problem: Could not move file into the directory"; exit; } echo "File uploaded successfully <hr>"; $fp = fopen($upfile, "r"); $contents = fread ($fp, filesize ($upfile)); fclose ($fp); $contents = strip_tags($contents); $fp = fopen ($upfile, "w"); fwrite ($fp, $contents); fclose($fp); echo "Preview of uploaded file contents: <hr>"; echo "$contents"; echo " <hr>"; $DEBUG=1; if ($DEBUG==1) echo "test: entering "; if (isset($_POST['submit'])) { $freeSpace=$MAX_FILE_SIZE; if ($freeSpace==0) echo "no space left "; else { if ($DEBUG==1) echo "test: good, copying file... "; $loctaille=$FUserFile_size; $realName=$FUserFile_name; if (!copy($FUserFile, "./images/$realName")) echo ("failed to copy $realName... "); else echo "file $FUserFile copied successfully. "; } // space left } // POST data received if ($DEBUG==1) echo "test: getting out to HTML "; ?> </form> </td> </tr> </table> </div> |
|||
| By: VGR | Date: 05/11/2004 07:57:00 | Type : Comment |
|
| here it is, corrected. Let's be clear : you were doing the "copy uploaded file" work thrice, you still had two typos I mentioned earlier, you were using variables as if Register_globals=On in php.ini (I doubt it's the case, let me know otherwise, but my code works anyway), you try to preview the uploaded data while it's impossible : output already started (it's toolate to issue Headers(image/jpg) etc. All you can do is issue an <IMG SRC="$upfile"> tag you also did the "test posted data" work after displaying the FORM, which is rather strange. It's more logical my way (you don't have to issue the FORM if you don't want to, just get out the "exit;" statements that you have and just don't copy uploaded file if incorrect) ---- source <?php $DEBUG=1; if (!isset($PHP_SELF)) $PHP_SELF=$_SERVER['PHP_SELF']; // treat data /* FYI : received data will be under the form : $_POST[] = Array ( [MAX_FILE_SIZE] => 3000000 [submit] => Send File ) $_FILES[] = Array ( [userfile] => Array ( [name] => ~del-me.jpg [type] => image/pjpeg [tmp_name] => C:\DOCUME~1\vgr\LOCALS~1\Temp\php9A.tmp [error] => 0 [size] => 16936 ) ) */ if (isset($_POST['submit'])) { // POSTed data present if ($DEBUG==1) echo "test: good POST, copying file... "; $MAX_FILE_SIZE=$_POST['MAX_FILE_SIZE']; $freeSpace=$MAX_FILE_SIZE; if ($DEBUG==1) echo "test: file oversize received $freeSpace (0 means 'too big') "; if ($freeSpace==0) echo "no space left "; else { // get data $userfile=$_FILES['userfile']; // analyse data if (!isset($userfile)) { echo "Problem: no file uploaded"; exit; } // else we can continue if ($userfile['size']==0) { echo "Problem: Uploaded file is zero in length"; exit; } if ($DEBUG==1) echo "file type received : {$userfile['type']} "; // NB : you lack a lot of image formats hereafter, particularly image/pjpeg and image/jpeg // I suggest to build an array of acceptable mime types and use in_array() if ($userfile_type != 'image/jpg') { echo "Problem: file is not an image"; exit; } if ($DEBUG==1) echo '<pre>'; if ($DEBUG==1) $upfile=$userfile['name']; else $upfile = "/home/hp-car/www/cars/images/".$upfile['name']; // _images doesn't exist if (move_uploaded_file($userfile['tmp_name'], $upfile)) { // typo again print "File is valid, and was successfully uploaded to $upfile. Here's some more debugging info:\n"; if ($DEBUG==1) print_r($_FILES); // fall-through } else { print "Possible file upload attack! Here's some debugging info:\n"; if ($DEBUG==1) print_r($_FILES); exit; } if ($DEBUG==1) echo '</pre>'; } // space left } // POST data received if ($DEBUG==1) echo "test: getting out to HTML "; // display form echo <<<EOS <form enctype="multipart/form-data" action="$PHP_SELF" method="post"><input type="hidden" name="MAX_FILE_SIZE" value="3000000"> Send this file: <input name="userfile" type="file"> <input name="submit" type="submit" value="Send File"> </form> EOS; /* strange/weird : </td> </tr> </table> </div> */ ?> |
|||
| By: dcatkin | Date: 05/11/2004 08:43:00 | Type : Comment |
|
| Now I've got your code put into the page, but it shows the code in the browser when you view it : Here it is. <?php session_start(); mysql_connect("localhost", "dcatkin", "hellfire") or die("(".mysql_errno().") Error:".mysql_error()); mysql_select_db( "cars" ) or die("(".mysql_errno().") Error:".mysql_error()); ?> <html> <head> <title>Upload</title> <meta http-equiv="Content-Type" content= "text/html; charset=iso-8859-1"> <script language="JavaScript" type="text/JavaScript"> <!-- function MM_reloadPage(init) { //reloads the window if Nav4 resized if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) { document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }} else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload(); } MM_reloadPage(true); //--> </script> <style type="text/css"> body { background-color: #0066CC; } div.c5 {position:absolute; width:587px; height:342px; z-index:1; left: 220px; top: 143px;} strong.c4 {font-size: 120%} div.c3 {text-align: center} a.c2 {font-size: 144%} td.c1 {font-size: 144%} </style> </head> <body> <div class="c3"> <table width="800" border="0" summary="Upload"> <tr> <td width="677" height="688" align="left" valign="top" bgcolor= "#00FFFF"> <table width="100%" border="0" summary="Upload"> <tr> <td height="682" valign="top" bgcolor="#00CCFF"> <table width="100%" border="0" bgcolor="#0033CC" summary= "Upload"> <tr> <td height="115"><img src="images/3dtext_21393.gif" alt="Hp-Car" width="790" height="106"></td> </tr> </table> <table width="120" border="0" align="left" summary="Hp-Car"> <tr> <td width="114" height="38" align="center" bgcolor="#3300CC" class="c1"><span class="c2"><a href= "<A HREF="http://hp-car.com/index.html">http://hp-car.com/index.html</A>"><img src="buttons/home.gif" alt= "parts/buttons/home.gif" width="100" height="37" border="0"> </a></span></td> </tr> <tr> <td align="center" bgcolor="#3300CC" class="c3"><a href= "<A HREF="http://hp-car.com/parts/index.php">http://hp-car.com/parts/index.php</A>" class="c2"><img src= "buttons/parts.gif" alt="buttons/parts.gif" width="100" height= "37" border="0"></a></td> </tr> <tr> <td align="center" bgcolor="#3300CC" class="c3"><a href= "<A HREF="http://hp-car.com/info/index.html">http://hp-car.com/info/index.html</A>" class="c2"><img src= "buttons/info.gif" alt="buttons/info.gif" width="100" height="37" border="0"></a></td> </tr> <tr> <td align="center" bgcolor="#3300CC" class="c3"><a href= "<A HREF="http://hp-car.com/engine/index.html">http://hp-car.com/engine/index.html</A>" class="c2"><img src= "buttons/engine.gif" alt="buttons/engine.gif" width="100" height= "37" border="0"></a></td> </tr> <tr> <td align="center" bgcolor="#3300CC" class="c3"><a href= "<A HREF="http://hp-car.com/users/index.html">http://hp-car.com/users/index.html</A>" class="c2"><img src= "buttons/user.gif" alt="buttons/user.gif" width="100" height="37" border="0"></a></td> </tr> <tr> <td align="center" bgcolor="#3300CC" class="c3"><a href= "<A HREF="http://hp-car.com/b+p/index.html">http://hp-car.com/b+p/index.html</A>" class="c2"><img src= "buttons/body.gif" alt="buttons/body.gif" width="100" height="37" border="0"></a></td> </tr> <tr> <td align="center" bgcolor="#3300CC" class="c3"><a href= "<A HREF="http://hp-car.com/cgi-bin/chat/chat.cgi">http://hp-car.com/cgi-bin/chat/chat.cgi</A>" class="c2"><img src= "buttons/chat.gif" alt="buttons/chat.gif" width="100" height="37" border="0"></a></td> </tr> <tr> <td align="center" bgcolor="#3300CC" class="c3"><a href= "<A HREF="http://hp-car.com/forum/index.php">http://hp-car.com/forum/index.php</A>" class="c2"><img src= "buttons/forums.gif" alt="parts/buttons/forums.gif" width="100" height="33" border="0"></a></td> </tr> <tr> <td align="center" bgcolor="#3300CC" class="c3"><a href= "<A HREF="http://hp-car.com/advert/index.html">http://hp-car.com/advert/index.html</A>" class="c2"><img src= "buttons/biz.gif" alt="parts/buttons/biz.gif" width="100" height= "37" border="0"></a></td> </tr> <tr> <td align="center" bgcolor="#3300CC" class="c3"><a href= "<A HREF="http://hp-car.com/gbook/jgb.php3">http://hp-car.com/gbook/jgb.php3</A>" class="c2"><img src= "buttons/guest.gif" alt="buttons/guest.gif" width="100" height= "37" border="0"></a></td> </tr> <tr> <td height="37" align="center" bgcolor="#3300CC" class="c3"><a href="<A HREF="http://hp-car.com/links/index.php">http://hp-car.com/links/index.php</A>" class="c2"><img src= "buttons/links.gif" alt="parts/buttons/links.gif" width="100" height="37" border="0"></a></td> </tr> <tr> <td height="23" valign="top" bgcolor="#0000CC"> <div class="c1 c3"><a href="<A HREF="http://hp-car.com/cars/index.php">http://hp-car.com/cars/index.php</A>" class="c2"><img src="buttons/CARS.GIF" alt="Button" width="100" height="37" border="0" lowsrc="/buttons/CARS.GIF"></a></div> </td> </tr> <tr> <td height="23" valign="top" bgcolor="#0000CC"> <div class="c1 c3"><a href= "<A HREF="http://hp-car.com/cgi-bin/search/search.pl">http://hp-car.com/cgi-bin/search/search.pl</A>" target="_self" class="c2"><img src="buttons/SEARCH.GIF" alt="Button" width="100" height="37" border="0" lowsrc="/buttons/SEARCH.GIF"></a></div> </td> </tr> <tr> <td height="35" align="center" valign="top" bgcolor="#00CCFF"><a href="<A HREF="http://www.redhat.com">http://www.redhat.com</A>" class="c2"><img src= "images/poweredby.png" alt="Button" width="88" height="31" border="0"></a></td> </tr> </table> <div id="Layer1" class="c5"> <div class="c3"> <table width="98%" border="0" bordercolor="#CCCCCC" bgcolor= "#00FFFF" summary="Upload"> <tr> <td height="26"> <?php $DEBUG=1; if (!isset($PHP_SELF)) $PHP_SELF=$_SERVER['PHP_SELF']; // treat data /* FYI : received data will be under the form : $_POST[] = Array ( [MAX_FILE_SIZE] => 3000000 [submit] => Send File ) $_FILES[] = Array ( [userfile] => Array ( [name] => ~del-me.jpg [type] => image/pjpeg [tmp_name] => C:\DOCUME~1\vgr\LOCALS~1\Temp\php9A.tmp [error] => 0 [size] => 16936 ) ) */ if (isset($_POST['submit'])) { // POSTed data present if ($DEBUG==1) echo "test: good POST, copying file... "; $MAX_FILE_SIZE=$_POST['MAX_FILE_SIZE']; $freeSpace=$MAX_FILE_SIZE; if ($DEBUG==1) echo "test: file oversize received $freeSpace (0 means 'too big') "; if ($freeSpace==0) echo "no space left "; else { // get data $userfile=$_FILES['userfile']; // analyse data if (!isset($userfile)) { echo "Problem: no file uploaded"; exit; } // else we can continue if ($userfile['size']==0) { echo "Problem: Uploaded file is zero in length"; exit; } if ($DEBUG==1) echo "file type received : {$userfile['type']} "; // NB : you lack a lot of image formats hereafter, particularly image/pjpeg and image/jpeg // I suggest to build an array of acceptable mime types and use in_array() if ($userfile_type != 'image/jpg') { echo "Problem: file is not an image"; exit; } if ($DEBUG==1) echo '<pre>'; if ($DEBUG==1) $upfile=$userfile['name']; else $upfile = "/home/hp-car/www/cars/images/".$upfile['name']; // _images doesn't exist if (move_uploaded_file($userfile['tmp_name'], $upfile)) { // typo again print "File is valid, and was successfully uploaded to $upfile. Here's some more debugging info:\n"; if ($DEBUG==1) print_r($_FILES); // fall-through } else { print "Possible file upload attack! Here's some debugging info:\n"; if ($DEBUG==1) print_r($_FILES); exit; } if ($DEBUG==1) echo '</pre>'; } // space left } // POST data received if ($DEBUG==1) echo "test: getting out to HTML "; // display form echo <<<EOS <form enctype="multipart/form-data" action="$PHP_SELF" method="post"><input type="hidden" name="MAX_FILE_SIZE" value="3000000"> Send this file: <input name="userfile" type="file"> <input name="submit" type="submit" value="Send File"> </form> EOS; /* strange/weird : </td> </tr> </table> </div> */ ?> </td> </tr> </table> </div> <div class="c3"> <table width="98%" border="0" summary="Upload"> <tr> <td><strong class="c4">A picture is worth 1,000 words, upload a picture of the car you have for sale here.</strong></td> </tr> </table> </div> </div> </td> </tr> </table> </td> </tr> </table> </div> </body> </html> |
|||
| By: VGR | Date: 06/11/2004 05:23:00 | Type : Comment |
|
| why ? <?php ... ?> are the tags supposed to work everywhere, anytime. try <? ... ?> if you want (allow_short_tags=On in php.ini), but this can't normally be an error Are you sure your webserver (Apache+PHP module, usually) is running ? Do you have the correct output of this ? : <? phpinfo(); ?> |
|||
| By: dcatkin | Date: 06/11/2004 23:51:00 | Type : Comment |
|
| I do know that php is running on the web server. I'll try changeing the tags and see if that helps. Tahnk you for your help. |
|||
| By: dcatkin | Date: 07/11/2004 00:03:00 | Type : Comment |
|
| test: good POST, copying file... test: file oversize received 3000000 (0 means 'too big') file type received : image/x-png Problem: file is not an image Now it gives me this message when uploading a file, and the code is not displaying on the page now, thank you. Heres the url <A HREF="http://hp-car.com/cars/upload_cars.php">http://hp-car.com/cars/upload_cars.php</A> Thank you David C. Atkin |
|||
| By: VGR | Date: 07/11/2004 00:12:00 | Type : Answer |
|
| that's NORMAL !!! Look in my code ! I told you that testing for file_type='image/jpg" was TOO RESTRICTIVE !!! you lack GIF, PNG, JPEG, PJPEG... at least. And why not SWF ? Look at my comments, I suggested building a static array of "allowed image types" (you do this list) and then use in_array() in the code to reject types outside that list easy, no ? let me know if you need more help |
|||
|
Do register to be able to answer |
|||
©2010 These pages are served without commercial sponsorship. (No popup ads, etc...). Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE.
Please DO link to this page!








