Undefined index for $_FILES


Results 1 to 6 of 6

Thread: Undefined index for $_FILES

  1. #1
    Join Date
    Oct 2000
    Location
    Sweden
    Posts
    494

    Undefined index for $_FILES

    Using my own created webform to send mails I get this "undefined index" message when trying to attach a file, and I can't for the life of me figure out why?
    Here's the script (sorry, comments are in Swedish):
    Code:
    <?php
    include ("includes/function_1.php");
    require_once ("Mail.php");
    include  ("Mail/mime.php");
    $adminmail="info@tuxit.se";
    $STATUS="R";
    $SORTERING="f_namn";
    $upload_dir="../uploads";
    //$reg_datum=today();
    	if(isset($_POST['submit']))
    	{
    		$subject=$_POST['subject'];
    		$nletter=$_POST['nletter'];
    		if ($subject =="" || $nletter == "") 
    		{
    			header("Location: skicka_mejl.php");
    //			print "Du måste ange ämne och skriva ett meddelande.";
    		}
    		else
    		{
    		// Ta hand om bilaga om det finns
    //		if(isset($_FILES['bifogad_fil']))
    //		{
    			$filnamn =  $_FILES['bilaga']['name'];
    			// Extension & storlek
    			$type_of_uploaded_file = substr($filnamn, strrpos($filnamn, '.') + 1);
    			$filstorlek = $_FILES['bilaga']["size"]/1024;
    			// Kopiera filen till tmp-dir
    			$path_of_uploaded_file = $upload_dir . $filnamn;
    			$tmp_path = $_FILES['bifogad_fil']["tmp_name"];
    			if(is_uploaded_file($tmp_path))
    			{
    				if(!copy($tmp_path,$path_of_uploaded_file))
    				{
     					$errors .= '\n error while copying the uploaded file';
    				}
    			}
    	// This for error checking
    			print $path_of_uploaded_file;
       			print "<pre>";
       			print_r($_FILES);
       			print "</pre>"; 
    //		} 
    		// Forma & skicka
    			$nletter = $_POST['nletter'];
    			$subject = $_POST['subject'];
    			$nletter = stripslashes($nletter);
    			$subject = stripslashes($subject);
    			$body = str_replace("rn","<br>",$nletter);
    			//Ovanstående formaterar meddelandet
    			$from = $adminmail;
    			 
    			anslutDB();
    			$resultat = $mysqli->query("SELECT * FROM medlem_reg WHERE status='$STATUS' AND epost>'' ORDER BY $SORTERING");
    			if ($resultat->num_rows > 0)  
    			{
    				while ($rad = $resultat->fetch_object())   {
    					$to = $rad->epost;
    			{
    // Note: if next line is uncommented mail is sent to all recipients.
    //	sendmail($from, $to, $subject, $body); 
    	// Stäng databas-anslutningen
    	$mysqli->close();
    //	header("Location: skicka_mejl.php");
      			}
    		}
    	}
    }
    }
    else
    {
    	print "<form action='skicka_mejl.php' method='post' enctype='multipart/form-data'>";
    	print "Ämne:<br>";
    	print "<input type='text' name='subject' size='20'><br>";
    	print "Meddelande:<br>";
    	print "<textarea name='nletter' cols='50' rows='6'></textarea><br>";
    	print "<input type='submit' name='submit' value='Skicka'></form>";
    	print "<label for='bilaga'>Välj en fil att bifoga:</label>";
    	print "<input type='file' name='bilaga'><br/>";
    	print "<a href=http://tuxit.nu/exempelsida> Klicka här </a>för att återgå till första-sidan.</p>";
    }
    ?>
    Everything in this script works except for the 3 lines with "$_FILES['bilaga']['name']", so the form in itself should be correct.
    For error checking, those lines
    print "<pre>";
    print_r($_FILES);
    print "</pre>";
    gives
    Array
    (
    )


    I tried using "$_POST['bilaga']" and "basename($_FILES['bilaga']['name'])", tried with all different kinds of quotes but no difference.
    I've googled like h..ll, no solution found helps - everything looks correct to me?
    The file I'm trying to upload is a text-file size 11 (it contains one line with a 9-digit number)
    php.ini has post_max_size = 8M upload_max_filesize = 2M

    Also same problem when I put the scripts on a public webserver where file uploads are used in other websites - so there must be something with this script??
    In pingvino veritas!

  2. #2
    Join Date
    Oct 2000
    Location
    Sweden
    Posts
    494
    HAAA!
    Found it at last - 2 days of testing, reading, searching... - and it's so simple:
    The "submit" must of course come after adding the attachment, not before!
    In pingvino veritas!

  3. #3
    Join Date
    Jul 2013
    Posts
    1
    YOU sir, are my HERO!

    I created an account here just to tell you this

    It's a 2+ year old threat but so what?
    Exactly -this- caused my problems too!

    Thanks, man... now I dont have to spend the time that you lost searching

  4. #4
    Join Date
    Jul 2013
    Posts
    1
    Thanks, I found out what the problem was. I had gssftp running at the same time as vsftpd. I just disabled gssftp from the services and it works fine now.

  5. #5
    Join Date
    Jul 2013
    Posts
    1
    thanks

  6. #6
    Join Date
    Jul 2013
    Posts
    1
    The scripts has written in PHP.It can be easily to create the webpage.Why can use array in final ?.I think this only the problem.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •