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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
shivers3000
Forum Newbie
Posts: 4
Joined: Tue Jan 27, 2004 10:38 am

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

Post 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();
?>
Gen-ik
DevNet Resident
Posts: 1059
Joined: Mon Aug 12, 2002 7:08 pm
Location: London. UK.

Post by Gen-ik »

Looks like you are missing some header() info.

Code: Select all

<?php

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

?>
shivers3000
Forum Newbie
Posts: 4
Joined: Tue Jan 27, 2004 10:38 am

Post by shivers3000 »

Thank you, I will give this a try.
Post Reply