0

Updated!

I have never had a problem with this before, i'm on a local server and UAC is turned off as well.

Here is my form, well, a dumbed down version of the form as there is a lot of text in there:

<form id="setup" name="setup" action="php/process_setup.php" method="post" enctype="multipart/form-data">
   <input type="text" name="cname" id="cname" value="" />
   <input type="text" name="splash" id="splash" />
   <input type="file" name="file"/>
   <input type="text" name="email" id="email" />
   <input type="password" name="password" id="password" />
   <input type="password" name="cpassword" id="cpassword" />
   <input type="submit" value="Submit" name="submit_setup" />
</form>

Here is the PHP im trying:

if ($_FILES["file"]["error"] > 0)
  {
  echo "Error: " . $_FILES["file"]["error"] . "<br>";
  }
else
  {
  echo "Upload: " . $_FILES["file"]["name"] . "<br>";
  echo "Type: " . $_FILES["file"]["type"] . "<br>";
  echo "Size: " . ($_FILES["file"]["size"] / 1024) . " kB<br>";
  echo "Stored in: " . $_FILES["file"]["tmp_name"];
  }

And here is the result:

Notice: Undefined index: file in C:\xampp\htdocs\ppa\php\process_setup.php on line 10

Notice: Undefined index: file in C:\xampp\htdocs\ppa\php\process_setup.php on line 16 Upload:

Notice: Undefined index: file in C:\xampp\htdocs\ppa\php\process_setup.php on line 17 Type:

Notice: Undefined index: file in C:\xampp\htdocs\ppa\php\process_setup.php on line 18 Size: 0 kB

Notice: Undefined index: file in C:\xampp\htdocs\ppa\php\process_setup.php on line 19 Stored in:

Edit 2

Just did a test to see if PHP has write permission, here is the code:

echo copy("1383778885275.jpg", "C:/xampp/tmp/1383778885275.jpg");

And the result was:

1

And the image IS in the tmp directory..

7
  • 1
    I don't know why you're using && isset($_FILES["file"]["tmp_name"]) && !empty($_FILES["file"]["tmp_name"]) because the tmp file doesn't exist "yet". So of course it will fail. Commented Nov 13, 2013 at 0:54
  • first step is to see if your initial if statement is being passed, are all of those isset and !empty correct? Commented Nov 13, 2013 at 0:55
  • empty() checks if variable is set as well, so isset() is not needed Commented Nov 13, 2013 at 1:01
  • I believe @Fred-ii is incorrect. Since you are if POSTING the FILE the FILE exists and has a tmp_name. But you should change '!empty($_FILES["file"]["tmp_name"] to isset($_FILES["file"]["tmp_name"]. Commented Nov 13, 2013 at 1:02
  • Updated my post using w3schools code, still no luck. Commented Nov 13, 2013 at 1:03

4 Answers 4

1

I am doing it in on a simple way , try having this:

if(!empty($_POST) && !empty($_FILES["file"]["name"]) ){ //check the following post values if not empty
    $name = $_FILES["file"]["name"];
    $temp = $_FILES["file"]["tmp_name"];
    $location= "../images/";
    if(move_uploaded_file($temp, $location.$name)) {
        echo "Uploaded!!!";
    } else {
        echo "Error:";
    }
} else {
    echo "Please choose a file to upload";
}
Sign up to request clarification or add additional context in comments.

1 Comment

where's your condition when post values have established?
1

You probably need to change !empty($_FILES["file"]["tmp_name"] to:

isset($_FILES["file"]["tmp_name"]

and if(move_uploaded_file($temp, $location.$name)) { to:

if(move_uploaded_file($temp, $location.basename($name))) {

Emphasis on basename().

Comments

1

According to your notice information ,the $_FILES is probably empty.You can check the following issues:

1.Make sure your directory has permissions for the tmp and upload directories.
2.Make sure the value of `file_uploads` option in `php.ini` is `On`

7 Comments

I have checked '2' and that is set to 'On'.
@Martyn Lee Ball ,well then that will be a permission problem.
I have also checked '1', but I can't see any additional users to give full access permission to. Currently: Authenticated users; SYSTEM; Administrators; Users. All have Full control..
@@Martyn Lee Ball ,another point,how about the size of your uploading file?php.ini also has a default limit.usually 8M by default.
I have checked that,it's only an image and doesn't go over that limit.
|
0

Thanks for all the help guys. It seems that there was an issue in some of the code I didn't include.. :/

Basically:

<form id="setup" name="setup" action="php/process_setup.php" method="post" enctype="multipart/form-data">

.....

....

<input type="file" name="logo"/>

...


.....

somewhere had some dodgy code I deleted

....

</form>

Thanks for the help.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.