Jump to content

PHP Multiple file upload error???


rahulephp

Recommended Posts

i think i am missing something in the below script:

It shows error an do not upload files to destination:

 

Let me know how to solve this:

 


  <?php


  if (isset($_POST[submit])) 
  
  {

  $uploadArray= array();
  $uploadArray[] = $_POST['uploadedfile'];
  $uploadArray[] = $_POST['uploadedfile2'];
  $uploadArray[] = $_POST['uploadedfile3'];


  foreach($uploadArray as $file) 
  {
	  $target_path = "upload/";

	  $target_path = $target_path . basename( $_FILES["$file"]['name']);


		if(move_uploaded_file($_FILES["$file"]['tmp_name'], $target_path)) 
			{

			echo "The file ". basename( $_FILES["$file"]['name'])." has been uploaded";

			}
	   else
				{

			echo "There was an error uploading the file, please try again!";

			 }

  		}



  }



  ?>





  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

  <html xmlns="http://www.w3.org/1999/xhtml">

  <head>

  <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />

  <title>Untitled Document</title>

  </head>



  <body>





  <form enctype="multipart/form-data" action="" method="POST">

  <p>

	 <input type="hidden" name="MAX_FILE_SIZE" value="100000" />

  Choose a file to upload:

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

  </p>

  <p>Choose a file to upload:

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

  </p>

  <p>Choose a file to upload:

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

  <br />

  <input name="submit" type="submit" id="submit" value="submit" />

  </p>

  </form>



  </body>

  </html>

 

Error Msg:


Notice: Undefined index: in E:\wamp\www\fileupload\index.php on line 25
There was an error uploading the file, please try again!
Notice: Undefined index: in E:\wamp\www\fileupload\index.php on line 22

Notice: Undefined index: in E:\wamp\www\fileupload\index.php on line 25
There was an error uploading the file, please try again!
Notice: Undefined index: in E:\wamp\www\fileupload\index.php on line 22

Notice: Undefined index: in E:\wamp\www\fileupload\index.php on line 25
There was an error uploading the file, please try again! 

Link to comment
Share on other sites

you can use $_FILES directly your file input boxes won't be available in $_POST

 

  <?php

  if (isset($_POST[submit])) 
  
  {

     foreach($_FILES as $file) 
     {
        $target_path = "upload/";
      
        $target_path = $target_path . basename( $file['name']);
      
      
         if(move_uploaded_file($file['tmp_name'], $target_path)) 
            {
      
            echo "The file ". basename( $file)." has been uploaded";
      
            }
         else
               {
      
            echo "There was an error uploading the file, please try again!";
      
             }
        }

  }

  ?>

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.