Files types

Can anyone point me in the right direction. I am trying to upload jpg
images and using the following piece of code
$myerror = "no";
$msg = "ok";
$img_types = array('image/jpeg','image/jpg','image/pjpeg');
if (!in_array($_FILES['imagefile']['type'],$img_types))
{
$msg = 'Problem: file is not jpg';
$myerror = "yes";
}
echo $msg;
When I try to download a jpg I still get the problem msg.
Is there something that I am doing wrong that I cant see or is there
another way to do this.
Thanks in advance

Bill
bill [ Mi, 19 September 2007 11:15 ] [ ID #1824292 ]

Re: Files types

Bill schreef:
> Can anyone point me in the right direction. I am trying to upload jpg
> images and using the following piece of code
> $myerror = "no";
> $msg = "ok";
> $img_types = array('image/jpeg','image/jpg','image/pjpeg');
> if (!in_array($_FILES['imagefile']['type'],$img_types))
> {
> $msg = 'Problem: file is not jpg';
> $myerror = "yes";
> }
> echo $msg;
> When I try to download a jpg I still get the problem msg.
> Is there something that I am doing wrong that I cant see or is there
> another way to do this.
> Thanks in advance
>

What is the output when you print $_FILES['imagefile']['type']?


JW
Janwillem Borleffs [ Mi, 19 September 2007 14:41 ] [ ID #1824293 ]

Re: Files types

Janwillem Borleffs wrote:
> Bill schreef:
>> Can anyone point me in the right direction. I am trying to upload jpg
>> images and using the following piece of code
>> $myerror = "no";
>> $msg = "ok";
>> $img_types = array('image/jpeg','image/jpg','image/pjpeg');
>> if (!in_array($_FILES['imagefile']['type'],$img_types))
>> {
>> $msg = 'Problem: file is not jpg';
>> $myerror = "yes";
>> }
>> echo $msg;
>> When I try to download a jpg I still get the problem msg.
>> Is there something that I am doing wrong that I cant see or is there
>> another way to do this.
>> Thanks in advance
>>
>
> What is the output when you print $_FILES['imagefile']['type']?
>
>
> JW

i tried
$newname = $_FILES['imagefile']['type'];
echo $newname;
and got nothing.
Is there something I have to do to make this work
Thanks
bill [ Mi, 19 September 2007 16:22 ] [ ID #1824295 ]

Re: Files types

Bill wrote:
> Janwillem Borleffs wrote:
>> Bill schreef:
>>> Can anyone point me in the right direction. I am trying to upload jpg
>>> images and using the following piece of code
>>> $myerror = "no";
>>> $msg = "ok";
>>> $img_types = array('image/jpeg','image/jpg','image/pjpeg');
>>> if (!in_array($_FILES['imagefile']['type'],$img_types))
>>> {
>>> $msg = 'Problem: file is not jpg';
>>> $myerror = "yes";
>>> }
>>> echo $msg;
>>> When I try to download a jpg I still get the problem msg.
>>> Is there something that I am doing wrong that I cant see or is there
>>> another way to do this.
>>> Thanks in advance
>>>
>>
>> What is the output when you print $_FILES['imagefile']['type']?
>>
>>
>> JW
>
> i tried
> $newname = $_FILES['imagefile']['type'];
> echo $newname;
> and got nothing.
> Is there something I have to do to make this work
> Thanks

Try with

var_dump($_FILES);

and see what is set in the variable when an upload has been done and
it's easier to see things if you look at the webpage source code than
looking at the output in the browser (browsers don't care about new lines).

--

//Aho
Shion [ Mi, 19 September 2007 17:05 ] [ ID #1824296 ]

Re: Files types

Bill wrote:
> i tried
> $newname = $_FILES['imagefile']['type'];
> echo $newname;
> and got nothing.
> Is there something I have to do to make this work
>

Make sure the form has the correct method/enctype defined:

<form method="post" action="..." enctype="multipart/form-data">
<input type="file" name="imagefile" />
</form>


JW
Janwillem Borleffs [ Mi, 19 September 2007 22:48 ] [ ID #1824299 ]
PHP » alt.php » Files types

Vorheriges Thema: PDF Maker
Nächstes Thema: secure email