PHWinfo banniere

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

Réponse
 
LinkBack Outils de la discussion
Vieux 18/02/2008, 11h07   #1
kodaliece@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut File upload problem

Hi All,

I am using a simple php script to learn file upload functionality in
php.

Below is my html form code:
<html>
<title>
File Upload FORM
</title>
<body>
<form action="upload_file.php" method="POST" enctype="multipart/form-
data">
Select your file: <input type="file" name="inputFile"
id="inputFile">
<BR>
<input type="submit" value="Upload">
</form>
</body>
</html>

and my upload_file.php file is:
<?php
// chekc the type of the content uploaded
if (($_FILES["inputFile"]["type"] == "image/gif") ||
($_FILES["inputFile"]["type"] == "image/jpg") ||
($_FILES["inputFile"]["type"] == "image/pjpeg") &&
($_FILES["inputFile"]["size"] > 20000))
{
if ($_FILES["inputFile"]["error"] > 0)
echo "Error: ".$_FILES["inputFile"]["error"]."<br/>";
else
{
if (file_exists("upload/".$_FILES["inputFile"]["name"]))
echo "Error: File \""."upload/".$_FILES["inputFile"]["name"]."\"
already exists!";
else
{
move_uploaded_file($_FILES["inputFile"]["tmp_name"], "upload/".
$_FILES["inputFile"]["name"]);
echo "Stored the file: ".$_FILES["inputFile"]["name"];
}
}
}
else
{
echo "Invalid File";
}
?>

But this is not uploading the file and is always printing "Invalid
File". So I tried to echo the file name, type, size and error values.
But its printing nothing. The same code worked with IIS. But, now I am
using tomcat and its not working.

Can any one please me on this.

Thanks in advance,
Mohan
  Réponse avec citation
Vieux 18/02/2008, 13h34   #2
Jerry Stuckle
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: File upload problem

kodaliece@gmail.com wrote:
> Hi All,
>
> I am using a simple php script to learn file upload functionality in
> php.
>
> Below is my html form code:
> <html>
> <title>
> File Upload FORM
> </title>
> <body>
> <form action="upload_file.php" method="POST" enctype="multipart/form-
> data">
> Select your file: <input type="file" name="inputFile"
> id="inputFile">
> <BR>
> <input type="submit" value="Upload">
> </form>
> </body>
> </html>
>
> and my upload_file.php file is:
> <?php
> // chekc the type of the content uploaded
> if (($_FILES["inputFile"]["type"] == "image/gif") ||
> ($_FILES["inputFile"]["type"] == "image/jpg") ||
> ($_FILES["inputFile"]["type"] == "image/pjpeg") &&
> ($_FILES["inputFile"]["size"] > 20000))
> {
> if ($_FILES["inputFile"]["error"] > 0)
> echo "Error: ".$_FILES["inputFile"]["error"]."<br/>";
> else
> {
> if (file_exists("upload/".$_FILES["inputFile"]["name"]))
> echo "Error: File \""."upload/".$_FILES["inputFile"]["name"]."\"
> already exists!";
> else
> {
> move_uploaded_file($_FILES["inputFile"]["tmp_name"], "upload/".
> $_FILES["inputFile"]["name"]);
> echo "Stored the file: ".$_FILES["inputFile"]["name"];
> }
> }
> }
> else
> {
> echo "Invalid File";
> }
> ?>
>
> But this is not uploading the file and is always printing "Invalid
> File". So I tried to echo the file name, type, size and error values.
> But its printing nothing. The same code worked with IIS. But, now I am
> using tomcat and its not working.
>
> Can any one please me on this.
>
> Thanks in advance,
> Mohan
>


What do you have in your $_FILES array? i.e.

echo "<pre>\n";
print_r($_FILES);
echo "</pre>\n";


--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

  Réponse avec citation
Vieux 18/02/2008, 14h20   #3
kodaliece@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: File upload problem

On Feb 18, 6:34pm, Jerry Stuckle <jstuck...@attglobal.net> wrote:
> kodali...@gmail.com wrote:
> > Hi All,

>
> > I am using a simple php script to learn file upload functionality in
> > php.

>
> > Below is my html form code:
> > <html>
> > <title>
> > File Upload FORM
> > </title>
> > <body>
> > <form action="upload_file.php" method="POST" enctype="multipart/form-
> > data">
> > Select your file: <input type="file" name="inputFile"
> > id="inputFile">
> > <BR>
> > <input type="submit" value="Upload">
> > </form>
> > </body>
> > </html>

>
> > and my upload_file.php file is:
> > <?php
> > // chekc the type of the content uploaded
> > if (($_FILES["inputFile"]["type"] == "image/gif") ||
> > ($_FILES["inputFile"]["type"] == "image/jpg") ||
> > ($_FILES["inputFile"]["type"] == "image/pjpeg") &&
> > ($_FILES["inputFile"]["size"] > 20000))
> > {
> > if ($_FILES["inputFile"]["error"] > 0)
> > echo "Error: ".$_FILES["inputFile"]["error"]."<br/>";
> > else
> > {
> > if (file_exists("upload/".$_FILES["inputFile"]["name"]))
> > echo "Error: File \""."upload/".$_FILES["inputFile"]["name"]."\"
> > already exists!";
> > else
> > {
> > move_uploaded_file($_FILES["inputFile"]["tmp_name"], "upload/".
> > $_FILES["inputFile"]["name"]);
> > echo "Stored the file: ".$_FILES["inputFile"]["name"];
> > }
> > }
> > }
> > else
> > {
> > echo "Invalid File";
> > }
> > ?>

>
> > But this is not uploading the file and is always printing "Invalid
> > File". So I tried to echo the file name, type, size and error values.
> > But its printing nothing. The same code worked with IIS. But, now I am
> > using tomcat and its not working.

>
> > Can any one please me on this.

>
> > Thanks in advance,
> > Mohan

>
> What do you have in your $_FILES array? i.e.
>
> echo "<pre>\n";
> print_r($_FILES);
> echo "</pre>\n";
>
> --
> ==================
> Remove the "x" from my email address
> Jerry Stuckle
> JDS Computer Training Corp.
> jstuck...@attglobal.net
> ==================- Hide quoted text -
>
> - Show quoted text -


I used ur piece of code:
echo "<pre>\n";
print_r($_FILES);
echo "</pre>\n";

It displayed the following:
Array
(
)


Noting is in $_FILES array variable. But, I could not why this is
happening.

Mohan
  Réponse avec citation
Vieux 18/02/2008, 14h51   #4
kodaliece@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: File upload problem

On Feb 18, 7:20pm, kodali...@gmail.com wrote:
> On Feb 18, 6:34pm, Jerry Stuckle <jstuck...@attglobal.net> wrote:
>
>
>
>
>
> > kodali...@gmail.com wrote:
> > > Hi All,

>
> > > I am using a simple php script to learn file upload functionality in
> > > php.

>
> > > Below is my html form code:
> > > <html>
> > > <title>
> > > File Upload FORM
> > > </title>
> > > <body>
> > > <form action="upload_file.php" method="POST" enctype="multipart/form-
> > > data">
> > > Select your file: <input type="file" name="inputFile"
> > > id="inputFile">
> > > <BR>
> > > <input type="submit" value="Upload">
> > > </form>
> > > </body>
> > > </html>

>
> > > and my upload_file.php file is:
> > > <?php
> > > // chekc the type of the content uploaded
> > > if (($_FILES["inputFile"]["type"] == "image/gif") ||
> > > ($_FILES["inputFile"]["type"] == "image/jpg") ||
> > > ($_FILES["inputFile"]["type"] == "image/pjpeg") &&
> > > ($_FILES["inputFile"]["size"] > 20000))
> > > {
> > > if ($_FILES["inputFile"]["error"] > 0)
> > > echo "Error: ".$_FILES["inputFile"]["error"]."<br/>";
> > > else
> > > {
> > > if (file_exists("upload/".$_FILES["inputFile"]["name"]))
> > > echo "Error: File \""."upload/"..$_FILES["inputFile"]["name"]."\"
> > > already exists!";
> > > else
> > > {
> > > move_uploaded_file($_FILES["inputFile"]["tmp_name"], "upload/".
> > > $_FILES["inputFile"]["name"]);
> > > echo "Stored the file: ".$_FILES["inputFile"]["name"];
> > > }
> > > }
> > > }
> > > else
> > > {
> > > echo "Invalid File";
> > > }
> > > ?>

>
> > > But this is not uploading the file and is always printing "Invalid
> > > File". So I tried to echo the file name, type, size and error values.
> > > But its printing nothing. The same code worked with IIS. But, now I am
> > > using tomcat and its not working.

>
> > > Can any one please me on this.

>
> > > Thanks in advance,
> > > Mohan

>
> > What do you have in your $_FILES array? i.e.

>
> > echo "<pre>\n";
> > print_r($_FILES);
> > echo "</pre>\n";

>
> > --
> > ==================
> > Remove the "x" from my email address
> > Jerry Stuckle
> > JDS Computer Training Corp.
> > jstuck...@attglobal.net
> > ==================- Hide quoted text-

>
> > - Show quoted text -

>
> I used ur piece of code:
> echo "<pre>\n";
> print_r($_FILES);
> echo "</pre>\n";
>
> It displayed the following:
> Array
> (
> )
>
> Noting is in $_FILES array variable. But, I could not why this is
> happening.
>
> Mohan- Hide quoted text -
>
> - Show quoted text -


I am using PHP 5.2.5, apache-tomcat-5.5.26. Somewhere on the net I
read that tomcat doesn't allow enctype="multipart/form-data". Is this
true? If so, what should be done?
  Réponse avec citation
Vieux 18/02/2008, 15h36   #5
The Natural Philosopher
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: File upload problem

kodaliece@gmail.com wrote:
> On Feb 18, 7:20 pm, kodali...@gmail.com wrote:
>> On Feb 18, 6:34 pm, Jerry Stuckle <jstuck...@attglobal.net> wrote:
>>
>>
>>
>>
>>
>>> kodali...@gmail.com wrote:
>>>> Hi All,
>>>> I am using a simple php script to learn file upload functionality in
>>>> php.
>>>> Below is my html form code:
>>>> <html>
>>>> <title>
>>>> File Upload FORM
>>>> </title>
>>>> <body>
>>>> <form action="upload_file.php" method="POST" enctype="multipart/form-
>>>> data">
>>>> Select your file: <input type="file" name="inputFile"
>>>> id="inputFile">
>>>> <BR>
>>>> <input type="submit" value="Upload">
>>>> </form>
>>>> </body>
>>>> </html>
>>>> and my upload_file.php file is:
>>>> <?php
>>>> // chekc the type of the content uploaded
>>>> if (($_FILES["inputFile"]["type"] == "image/gif") ||
>>>> ($_FILES["inputFile"]["type"] == "image/jpg") ||
>>>> ($_FILES["inputFile"]["type"] == "image/pjpeg") &&
>>>> ($_FILES["inputFile"]["size"] > 20000))
>>>> {
>>>> if ($_FILES["inputFile"]["error"] > 0)
>>>> echo "Error: ".$_FILES["inputFile"]["error"]."<br/>";
>>>> else
>>>> {
>>>> if (file_exists("upload/".$_FILES["inputFile"]["name"]))
>>>> echo "Error: File \""."upload/".$_FILES["inputFile"]["name"]."\"
>>>> already exists!";
>>>> else
>>>> {
>>>> move_uploaded_file($_FILES["inputFile"]["tmp_name"], "upload/".
>>>> $_FILES["inputFile"]["name"]);
>>>> echo "Stored the file: ".$_FILES["inputFile"]["name"];
>>>> }
>>>> }
>>>> }
>>>> else
>>>> {
>>>> echo "Invalid File";
>>>> }
>>>> ?>
>>>> But this is not uploading the file and is always printing "Invalid
>>>> File". So I tried to echo the file name, type, size and error values.
>>>> But its printing nothing. The same code worked with IIS. But, now I am
>>>> using tomcat and its not working.
>>>> Can any one please me on this.
>>>> Thanks in advance,
>>>> Mohan
>>> What do you have in your $_FILES array? i.e.
>>> echo "<pre>\n";
>>> print_r($_FILES);
>>> echo "</pre>\n";
>>> --
>>> ==================
>>> Remove the "x" from my email address
>>> Jerry Stuckle
>>> JDS Computer Training Corp.
>>> jstuck...@attglobal.net
>>> ==================- Hide quoted text -
>>> - Show quoted text -

>> I used ur piece of code:
>> echo "<pre>\n";
>> print_r($_FILES);
>> echo "</pre>\n";
>>
>> It displayed the following:
>> Array
>> (
>> )
>>
>> Noting is in $_FILES array variable. But, I could not why this is
>> happening.
>>
>> Mohan- Hide quoted text -
>>
>> - Show quoted text -

>
> I am using PHP 5.2.5, apache-tomcat-5.5.26. Somewhere on the net I
> read that tomcat doesn't allow enctype="multipart/form-data". Is this
> true? If so, what should be done?


works for me. check that file uploading is turned on..think there is a
php.ini switch..

  Réponse avec citation
Vieux 19/02/2008, 03h28   #6
kodaliece@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: File upload problem

On Feb 18, 8:36pm, The Natural Philosopher <a...@b.c> wrote:
> kodali...@gmail.com wrote:
> > On Feb 18, 7:20 pm, kodali...@gmail.com wrote:
> >> On Feb 18, 6:34 pm, Jerry Stuckle <jstuck...@attglobal.net> wrote:

>
> >>> kodali...@gmail.com wrote:
> >>>> Hi All,
> >>>> I am using a simple php script to learn file upload functionality in
> >>>> php.
> >>>> Below is my html form code:
> >>>> <html>
> >>>> <title>
> >>>> File Upload FORM
> >>>> </title>
> >>>> <body>
> >>>> <form action="upload_file.php" method="POST" enctype="multipart/form-
> >>>> data">
> >>>> Select your file: <input type="file" name="inputFile"
> >>>> id="inputFile">
> >>>> <BR>
> >>>> <input type="submit" value="Upload">
> >>>> </form>
> >>>> </body>
> >>>> </html>
> >>>> and my upload_file.php file is:
> >>>> <?php
> >>>> // chekc the type of the content uploaded
> >>>> if (($_FILES["inputFile"]["type"] == "image/gif") ||
> >>>> ($_FILES["inputFile"]["type"] == "image/jpg") ||
> >>>> ($_FILES["inputFile"]["type"] == "image/pjpeg") &&
> >>>> ($_FILES["inputFile"]["size"] > 20000))
> >>>> {
> >>>> if ($_FILES["inputFile"]["error"] > 0)
> >>>> echo "Error: ".$_FILES["inputFile"]["error"]."<br/>";
> >>>> else
> >>>> {
> >>>> if (file_exists("upload/".$_FILES["inputFile"]["name"]))
> >>>> echo "Error: File \""."upload/".$_FILES["inputFile"]["name"]."\"
> >>>> already exists!";
> >>>> else
> >>>> {
> >>>> move_uploaded_file($_FILES["inputFile"]["tmp_name"], "upload/".
> >>>> $_FILES["inputFile"]["name"]);
> >>>> echo "Stored the file: ".$_FILES["inputFile"]["name"];
> >>>> }
> >>>> }
> >>>> }
> >>>> else
> >>>> {
> >>>> echo "Invalid File";
> >>>> }
> >>>> ?>
> >>>> But this is not uploading the file and is always printing "Invalid
> >>>> File". So I tried to echo the file name, type, size and error values.
> >>>> But its printing nothing. The same code worked with IIS. But, now I am
> >>>> using tomcat and its not working.
> >>>> Can any one please me on this.
> >>>> Thanks in advance,
> >>>> Mohan
> >>> What do you have in your $_FILES array? i.e.
> >>> echo "<pre>\n";
> >>> print_r($_FILES);
> >>> echo "</pre>\n";
> >>> --
> >>> ==================
> >>> Remove the "x" from my email address
> >>> Jerry Stuckle
> >>> JDS Computer Training Corp.
> >>> jstuck...@attglobal.net
> >>> ==================- Hide quoted text -
> >>> - Show quoted text -
> >> I used ur piece of code:
> >> echo "<pre>\n";
> >> print_r($_FILES);
> >> echo "</pre>\n";

>
> >> It displayed the following:
> >> Array
> >> (
> >> )

>
> >> Noting is in $_FILES array variable. But, I could not why this is
> >> happening.

>
> >> Mohan- Hide quoted text -

>
> >> - Show quoted text -

>
> > I am using PHP 5.2.5, apache-tomcat-5.5.26. Somewhere on the net I
> > read that tomcat doesn't allow enctype="multipart/form-data". Is this
> > true? If so, what should be done?

>
> works for me. check that file uploading is turned on..think there is a
> php.ini switch..- Hide quoted text -
>
> - Show quoted text -


Hi,
File Uploading is turned on in php.ini file. The same program worked
for me when I run on IIS. But is not working when I run it with tomcat.
  Réponse avec citation
Vieux 19/02/2008, 03h38   #7
Jerry Stuckle
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: File upload problem

kodaliece@gmail.com wrote:
> On Feb 18, 8:36 pm, The Natural Philosopher <a...@b.c> wrote:
>> kodali...@gmail.com wrote:
>>> On Feb 18, 7:20 pm, kodali...@gmail.com wrote:
>>>> On Feb 18, 6:34 pm, Jerry Stuckle <jstuck...@attglobal.net> wrote:
>>>>> kodali...@gmail.com wrote:
>>>>>> Hi All,
>>>>>> I am using a simple php script to learn file upload functionality in
>>>>>> php.
>>>>>> Below is my html form code:
>>>>>> <html>
>>>>>> <title>
>>>>>> File Upload FORM
>>>>>> </title>
>>>>>> <body>
>>>>>> <form action="upload_file.php" method="POST" enctype="multipart/form-
>>>>>> data">
>>>>>> Select your file: <input type="file" name="inputFile"
>>>>>> id="inputFile">
>>>>>> <BR>
>>>>>> <input type="submit" value="Upload">
>>>>>> </form>
>>>>>> </body>
>>>>>> </html>
>>>>>> and my upload_file.php file is:
>>>>>> <?php
>>>>>> // chekc the type of the content uploaded
>>>>>> if (($_FILES["inputFile"]["type"] == "image/gif") ||
>>>>>> ($_FILES["inputFile"]["type"] == "image/jpg") ||
>>>>>> ($_FILES["inputFile"]["type"] == "image/pjpeg") &&
>>>>>> ($_FILES["inputFile"]["size"] > 20000))
>>>>>> {
>>>>>> if ($_FILES["inputFile"]["error"] > 0)
>>>>>> echo "Error: ".$_FILES["inputFile"]["error"]."<br/>";
>>>>>> else
>>>>>> {
>>>>>> if (file_exists("upload/".$_FILES["inputFile"]["name"]))
>>>>>> echo "Error: File \""."upload/".$_FILES["inputFile"]["name"]."\"
>>>>>> already exists!";
>>>>>> else
>>>>>> {
>>>>>> move_uploaded_file($_FILES["inputFile"]["tmp_name"], "upload/".
>>>>>> $_FILES["inputFile"]["name"]);
>>>>>> echo "Stored the file: ".$_FILES["inputFile"]["name"];
>>>>>> }
>>>>>> }
>>>>>> }
>>>>>> else
>>>>>> {
>>>>>> echo "Invalid File";
>>>>>> }
>>>>>> ?>
>>>>>> But this is not uploading the file and is always printing "Invalid
>>>>>> File". So I tried to echo the file name, type, size and error values.
>>>>>> But its printing nothing. The same code worked with IIS. But, now I am
>>>>>> using tomcat and its not working.
>>>>>> Can any one please me on this.
>>>>>> Thanks in advance,
>>>>>> Mohan
>>>>> What do you have in your $_FILES array? i.e.
>>>>> echo "<pre>\n";
>>>>> print_r($_FILES);
>>>>> echo "</pre>\n";
>>>>> --
>>>>> ==================
>>>>> Remove the "x" from my email address
>>>>> Jerry Stuckle
>>>>> JDS Computer Training Corp.
>>>>> jstuck...@attglobal.net
>>>>> ==================- Hide quoted text -
>>>>> - Show quoted text -
>>>> I used ur piece of code:
>>>> echo "<pre>\n";
>>>> print_r($_FILES);
>>>> echo "</pre>\n";
>>>> It displayed the following:
>>>> Array
>>>> (
>>>> )
>>>> Noting is in $_FILES array variable. But, I could not why this is
>>>> happening.
>>>> Mohan- Hide quoted text -
>>>> - Show quoted text -
>>> I am using PHP 5.2.5, apache-tomcat-5.5.26. Somewhere on the net I
>>> read that tomcat doesn't allow enctype="multipart/form-data". Is this
>>> true? If so, what should be done?

>> works for me. check that file uploading is turned on..think there is a
>> php.ini switch..- Hide quoted text -
>>
>> - Show quoted text -

>
> Hi,
> File Uploading is turned on in php.ini file. The same program worked
> for me when I run on IIS. But is not working when I run it with tomcat.
>


I would suggest, then, you follow up in a tomcat newsgroup. The fact it
works on IIS says your PHP code is fine.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

  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 17h33.


É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,29027 seconds with 15 queries