Jump to content

$_FILES[userfile] is displaying no value.


amorphous4u

Recommended Posts

Hi,

 

I am trying to upload an image to my server using below php code:

 

html

 

<td width="116"><FORM ENCTYPE="multipart/form-data" ACTION="_URL_" METHOD=POST>Upload your photo:

                <td width="156"><INPUT NAME="userfile" TYPE="file"></td>

 

 

<?php

$userfile = $_POST['userfile'];

echo "1".$userfile;

echo "2".$_FILES['$userfile'];

echo "3".$_FILES['userfile'];

if((!empty($_FILES["userfile"])) && ($_FILES['userfile']['error'] == 0)) {

  //Check if the file is JPEG image and it's size is less than 350Kb

  $filename = basename($_FILES['userfile']['name']);

  $ext = substr($filename, strrpos($filename, '.') + 1);

  if (($ext == "jpg") && ($_FILES["userfile"]["type"] == "image/jpeg") &&

    ($_FILES["userfile"]["size"] < 350000)) {

    //Determine the path to which we want to save this file

      $newname = dirname(__FILE__).'/upload/'.$filename;

      //Check if the file with the same name is already exists on the server

      if (!file_exists($newname)) {

        //Attempt to move the uploaded file to it's new place

        if ((move_uploaded_file($_FILES['userfile']['tmp_name'],$newname))) {

          echo "It's done! The file has been saved as: ".$newname;

        } else {

          echo "Error: A problem occurred during file upload!";

        }

      } else {

        echo "Error: File ".$_FILES["userfile"]["name"]." already exists";

      }

  } else {

    echo "Error: Only .jpg images under 350Kb are accepted for upload";

  }

} else {

echo "Error: No file uploaded";

echo "4".$filename;

}

?>

 

I am getting output as:

 

1C:\\Documents and Settings\\All Users\\Documents\\My Pictures\\Sample Pictures\\Sunset.jpg

2

3

Error: No file uploaded

4

 

It seems life $_FILES['$userfile'] is not capturing any value.

 

Please help me.

 

Regards,

Link to comment
Share on other sites

The results seam kinda weird as

$userfile = $_POST['userfile'];
echo "1".$userfile;

 

shouldn't give you the file path!

 

try this

<FORM ENCTYPE="multipart/form-data" ACTION="" METHOD=POST>Upload your photo:
<INPUT NAME="userfile" TYPE="file">
<input type="submit">
</form>


<?php
$userfile = $_FILES['userfile']['name'];
echo "1".$userfile;
if((!empty($_FILES["userfile"])) && ($_FILES['userfile']['error'] == 0)) {
  //Check if the file is JPEG image and it's size is less than 350Kb
  $filename = basename($_FILES['userfile']['name']);
  $ext = substr($filename, strrpos($filename, '.') + 1);
  if (($ext == "jpg") && ($_FILES["userfile"]["type"] == "image/jpeg") &&
    ($_FILES["userfile"]["size"] < 350000)) {
    //Determine the path to which we want to save this file
      $newname = dirname(__FILE__).'/upload/'.$filename;
      //Check if the file with the same name is already exists on the server
      if (!file_exists($newname)) {
        //Attempt to move the uploaded file to it's new place
        if ((move_uploaded_file($_FILES['userfile']['tmp_name'],$newname))) {
           echo "It's done! The file has been saved as: ".$newname;
        } else {
           echo "Error: A problem occurred during file upload!";
        }
      } else {
         echo "Error: File ".$_FILES["userfile"]["name"]." already exists";
      }
  } else {
     echo "Error: Only .jpg images under 350Kb are accepted for upload";
  }
} else {
echo "Error: No file uploaded";
echo "2".$filename;
}
?>

Link to comment
Share on other sites

I aaded error reporting and getting these messages.

 

Notice: Undefined index: music in /home/himachal/public_html/******.php on line 53

 

Notice: Undefined index: accepted in /home/himachal/public_html/******.php on line 87

 

Notice: Undefined variable: i in /home/himachal/public_html/******.php on line 159

1C:\\Documents and Settings\\All Users\\Documents\\My Pictures\\Sample Pictures\\Winter.jpg

Notice: Undefined index: userfile in /home/himachal/public_html/******.php on line 276

2Error: No file uploaded

Notice: Undefined variable: filename in /home/himachal/public_html/******.php on line 302

3

 

 

Regards,

Link to comment
Share on other sites

I even added a variable to see if the file path is getting captured

This is the output i am getting now

 

C:\\Documents and Settings\\All Users\\Documents\\My Pictures\\Sample Pictures\\Winter.jpg

Notice: Undefined index: userfile in /home/himachal/public_html/registerfirst.php on line 7

1Error: No file uploaded

Notice: Undefined variable: filename in /home/himachal/public_html/registerfirst.php on line 33

2

 

Please help me I am stuck with the last feature of my registration form.

 

Regards,

 

Link to comment
Share on other sites

Please use the following code for debugging -

 

echo "<pre>";
echo "POST:";
print_r($_POST);
echo "FILES:";
print_r($_FILES);
echo "</pre>";

 

What does the above show AFTER the form has been submitted?

 

Edit: And you should check the actual values of the settings using a phpinfo(); statement, because there is always a chance that the php.ini that you are examining is not the one that php is using.

Link to comment
Share on other sites

the code you posted does have problems but the results you say your getting don't match, hence giving you some other code to test with, however that seams to be failing so either something very strange is going on or I'm not getting the whole story!

 

Here is a very basic version, if this failed it should at least let us know why! with some details

<?php
if(isset($_POST['submit']))
{
echo "<pre>";
var_dump($_FILES["userfile"]);
echo "</pre>";
if($_FILES["userfile"]["error"] == 0)
{
	if(move_uploaded_file($_FILES["userfile"]["tmp_name"],$_FILES["userfile"]["name"]) or die("Problems with upload"))
	{
		echo "Upload: {$_FILES["userfile"]["name"]}";
	}else{
		echo "FAILED: {$_FILES["userfile"]["name"]}";
	}
}else{
	echo "error: ".$_FILES["userfile"]["error"];
}
}
?>
<form action="" method="post" enctype="multipart/form-data">
  <input name="userfile" type="file" /><br />
  <input type="submit" name="submit" value="Send files" />
</form>

Link to comment
Share on other sites

Hi,

 

This is what i am getting after adding your code.

POST:Array

(

    [membershiptype] => 1

    [login] => time

    [password] => time

    [repassword] =>

    [gender] => 1

    [fname] =>

    [mname] =>

    [lname] =>

    [fathername] =>

    [profilecreatedby] => 1

    [dob] =>

    [birthHour] => 00

    [birthMin] => 00

    [birthSec] => 00

    [pob] =>

    [height] => 0

    [weight] => 0

    [complexion] => 0

    [bloodgroup] => 1

    [bodytype] => 1

    [maritalstatus] => 6

    [religion] => None

    [caste] => 1

    [subcaste] =>

    [gotra] =>

    [maternalcaste] =>

    [mothertongue] =>

    [manglik] => 1

    [horoscope] => 1

    [nakshatra] => none

    [education] =>

    [occupation] =>

    [income] => 0

    [hobbies] =>

    [interests] =>

    [music] =>

    [reads] =>

    [movies] =>

    [sports] =>

    [cuisine] =>

    [dress] =>

    [agefrom] =>

    [ageto] =>

    [p_maritalstatus] => 6

    [heightfrom] => 0

    [heightto] => 0

    [p_complexion] => 7

    [p_bodytype] => 1

    [p_religion] =>

    [p_mothertongue] =>

    [p_education] =>

    [p_occupation] =>

    [p_city] =>

    [p_state] =>

    [p_country] =>

    =>

    [address] =>

    [city] =>

    [district] =>

    [state] =>

    [country] =>

    [phone] =>

    [mobile] =>

    [agentid] =>

    [aboutu] =>

    [aboutfamily] =>

    [userfile] => C:\\Documents and Settings\\All Users\\Documents\\My Pictures\\Sample Pictures\\Winter.jpg

    [agreecheck] => on

    [action] => Submit!

)

FILES:Array

(

)

Notice: Undefined index: userfile in /home/himachal/public_html/registerfirst.php on line 283

1Error: No file uploaded

Notice: Undefined variable: filename in /home/himachal/public_html/registerfirst.php on line 309

2

 

Regards,

Link to comment
Share on other sites

The fact that the $_FILES array is empty but the $_POST array has values, means one or more of the following -

 

1) Uploads are not enabled on your server,

2) Your form is invalid to the point that the browser cannot figure it out after some point or that it is not a valid upload form,

3) There is no valid type="file" form field.

Link to comment
Share on other sites

I did wht u asked i ran the code u gave me and nothing happened.

 

I checked the error log and got this

 

[13-Jun-2009 20:54:22] PHP Warning:  PHP Startup: Unable to load dynamic library '/usr/local/lib/php/extensions/no-debug-non-zts-20060613/session.so' - /usr/local/lib/php/extensions/no-debug-non-zts-20060613/session.so: cannot open shared object file: No such file or directory in Unknown on line 0

Link to comment
Share on other sites

I'm going to bet this is all due to invalid form(s), even when using the code that MadTechie posted (which apparently gave no results), which I'll guess was probably added to existing code in the file instead of being used by itself.

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.