This is a discussion on Need help with retrieving images...coding is correct according to tutorials within the PHP Language forums, part of the PHP Programming Forums category; Can someone tell me what I am missing? I have looked at a ton of tutorials about retrieving images as ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
Can someone tell me what I am missing? I have looked at a ton of
tutorials about retrieving images as an image instead of binary from a file. I have verified the image goes into the file perfect. Thanks in advance <?PHP require_once('common.php'); session_start(); startFormHeader(); $name = $_FILES['userfile']['name']; $size = $_FILES['userfile']['size']; $tempFile = $_FILES['userfile']['tmp_name']; if ($userfile=='none') { echo "Problem: no file uploaded"; exit; } if ($size==0) { echo "Problem: uploaded file is zero length"; exit; } if (!is_uploaded_file($userfile)) { echo "problem: possible file upload attack"; exit; } $upfile ='showVehicle/'.$userfile_name; $copy = copy($_FILES['userfile']['tmp_name'],"showVehicle/".$name); if(!$copy) echo "System error: was not able to load image"; else echo"File uploaded successfully<br><br>"; $grab = "showVehicle/".$name; $fp = fopen($grab, "rb"); $contents = fread($fp, filesize($grab)); fclose($fp); footer(); ?> |
|
|||
|
I didnt really look at your code becouse I do not understand the question,
you verified the image goes into a file, so whats the problem? -- Mike Bradley http://www.gzentools.com -- free online php tools "lifeAfter76" <lifeafter76@yahoo.com> wrote in message news:1fae5b12.0401270825.1a72352@posting.google.co m... > Can someone tell me what I am missing? I have looked at a ton of > tutorials about retrieving images as an image instead of binary from a > file. > I have verified the image goes into the file perfect. > > Thanks in advance > > <?PHP > require_once('common.php'); > session_start(); > > startFormHeader(); > > $name = $_FILES['userfile']['name']; > > $size = $_FILES['userfile']['size']; > $tempFile = $_FILES['userfile']['tmp_name']; > if ($userfile=='none') > { > echo "Problem: no file uploaded"; > exit; > } > > if ($size==0) > { > echo "Problem: uploaded file is zero length"; > exit; > } > > if (!is_uploaded_file($userfile)) > { > echo "problem: possible file upload attack"; > exit; > } > > > $upfile ='showVehicle/'.$userfile_name; > > $copy = copy($_FILES['userfile']['tmp_name'],"showVehicle/".$name); > > > if(!$copy) > echo "System error: was not able to load image"; > else > echo"File uploaded successfully<br><br>"; > > > > $grab = "showVehicle/".$name; > $fp = fopen($grab, "rb"); > $contents = fread($fp, filesize($grab)); > > fclose($fp); > > > footer(); > ?> |
|
|||
|
lifeAfter76 a écrit le 27/01/2004 :
[...] > $grab = "showVehicle/".$name; > $fp = fopen($grab, "rb"); > $contents = fread($fp, filesize($grab)); Before sending $contents to the webclient, you must tell him it's an image you're sending him otherwise it will show it as text. So use header() before sending the file content : <?php header("Content-type: image/png"); //Header for a PNG file echo $contents; ?> |
|
|||
|
lifeAfter76 wrote:
> > Can someone tell me what I am missing? I have looked at a ton of > tutorials about retrieving images as an image instead of binary from a > file. > I have verified the image goes into the file perfect. > > Thanks in advance > > <?PHP > require_once('common.php'); > session_start(); > > startFormHeader(); > > $name = $_FILES['userfile']['name']; > > $size = $_FILES['userfile']['size']; > $tempFile = $_FILES['userfile']['tmp_name']; > if ($userfile=='none') > { > echo "Problem: no file uploaded"; > exit; > } > > if ($size==0) > { > echo "Problem: uploaded file is zero length"; > exit; > } > > if (!is_uploaded_file($userfile)) > { > echo "problem: possible file upload attack"; > exit; > } > > $upfile ='showVehicle/'.$userfile_name; > > $copy = copy($_FILES['userfile']['tmp_name'],"showVehicle/".$name); > > if(!$copy) > echo "System error: was not able to load image"; > else > echo"File uploaded successfully<br><br>"; > > $grab = "showVehicle/".$name; > $fp = fopen($grab, "rb"); > $contents = fread($fp, filesize($grab)); > > fclose($fp); > > footer(); > ?> Unless I'm missing something, you haven't described the problem. Please tell us what the problem is and what, if any error messages you get. If your script works in some cases, but not others, let us know and note the differences. Shawn -- Shawn Wilson shawn@glassgiant.com http://www.glassgiant.com |
|
|||
|
lifeAfter76 wrote:
> Can someone tell me what I am missing? I have looked at a ton of > tutorials about retrieving images as an image instead of binary from a > file. > I have verified the image goes into the file perfect. > > Thanks in advance > > <?PHP > require_once('common.php'); > session_start(); > > startFormHeader(); > > $name = $_FILES['userfile']['name']; > > $size = $_FILES['userfile']['size']; > $tempFile = $_FILES['userfile']['tmp_name']; > if ($userfile=='none') $userfile is not defined anywhere... |