PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > alt.php > Files types
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
Files types

Réponse
 
LinkBack Outils de la discussion
Vieux 19/09/2007, 10h15   #1
Bill
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut 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
  Réponse avec citation
Vieux 19/09/2007, 13h41   #2
Janwillem Borleffs
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut 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
  Réponse avec citation
Vieux 19/09/2007, 15h22   #3
Bill
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut 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
  Réponse avec citation
Vieux 19/09/2007, 16h05   #4
J.O. Aho
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut 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
  Réponse avec citation
Vieux 19/09/2007, 21h48   #5
Janwillem Borleffs
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut 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


  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 01h21.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,11280 seconds with 13 queries