Page 1 of 1

probs.. image from file is binary...code seems correct..help

Posted: Tue Jan 27, 2004 10:38 am
by shivers3000
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();
?>

Posted: Tue Jan 27, 2004 12:44 pm
by Gen-ik
Looks like you are missing some header() info.

Code: Select all

<?php

header("Content-Type: image/jpeg");
readfile("theImage.jpg");

?>

Posted: Tue Jan 27, 2004 1:21 pm
by shivers3000
Thank you, I will give this a try.