|
Posted by Richard Levasseur on 07/08/06 09:25
Lee wrote:
> Doesn't the mime type have to do with how you view it?
>
> If I use this php code, then it still doesn't display properly. How do
> I bring it in with it knowing that it should be in binary? I tried
> using base64_encode or base64_decode in the code but it doesn't seem to
> do the trick. I couldn't try something like convert_uuencode because I
> don't have php5.
> Thanks!
>
> <?
> $imageFile='graffiti.jpg';
>
> // display the image
> header("Content-Type: image/jpeg");
> $content = file_get_contents( $imageFile);
> // $content = base64_decode($content);
> print $content;
> ?>
>
> flamer die.spam@hotmail.com wrote:
> > you need to set the mime type or yes it will be binary BS.
> >
> > type=image/jpeg
> >
> > have a look at how thumbnail generators do it.
> >
> > flamer.
> >
> > Lee wrote:
> >
> > > Hi, I am reading in a huge post request that represents an image with
> > > the php file below. The resultant file should be in jpg format, but it
> > > comes in weird. Below my php file, I show the beginning of a regular
> > > jpg file and the beginning of what I actually write to the file. I'm
> > > sure it's a conversion issue but I don't know what. Any help?
> > >
> > > <?
> > > // open the log file
> > > $filename='log.txt';
> > > $imageFile='graffiti.jpg';
> > >
> > > // write the image to jpeg
> > > $imageString = $_POST['image'];
> > > $imageString = urldecode($imageString);
> > > //$imageString = stripslashes($imageString);
> > > $fpImage=fopen($imageFile,'w+b'); //remove the binary?
> > > fwrite($fpImage,$imageString);
> > > fclose($fpImage);
> > >
> > > // write to the log file
> > > $str = $imageString;
> > > $str = date('G:i:s',time()) . "\n\n" . $str;
> > > $logFp=fopen($filename,'w+');
> > > fwrite($logFp,$str);
> > > fclose($logFp);
> > >
> > >
> > > // display the log file
> > > header("Content-type: text/plain");
> > > include $filename;
> > > ?>
> > >
> > > What I write to file:
> > > ÿØÿà \0JFIF\0\0\0\0\0\0ÿÛ\0C\0
> > >
> > > $.\' \",#(7),01444\'9=82<.342ÿÛ\0C
> > >
> > > 2!!22222222222222222222222222222222222222222222222222ÿÀ\0��\"\0ÿÄ\0\0\0\0\0\0\0\0\0\0\0
> > >
> > > What a regular jpg looks like:
> > > ÿØÿà\0JFIF\0\0\0\0\0\0ÿÛ\0C\0
> > >
> > > $.\' \",#(7),01444\'9=82<.342ÿÛ\0C
Try using the super global $_FILES. There are a couple of better whys
to copy files in php other than directly from $_POST. After a post,
files are automatically saved in a temporary location, and all you have
to do is copy/rename them to where you want.
Its in the manual somewhere, i can't recall where exactly though,
probably in the section about file upload handling or superglobals.
Navigation:
[Reply to this message]
|