Please help, I have designed a form, that contains an upload button. The form can only take file upto the size of 1mb. Every time I press the submitbutton I get:

Notice: Undefined index: myfile in F:\wamp\www\Site\CRUD\Upload\insertscript.php on line 9
Invalid file type

this is my form and below is my upload code please help.

<form action="CRUD/Upload/insertscript.php" method="post" name="signup" id="signup" onSubmit="MM_validateForm('scriptid','','R','scriptname','','R','mission','','R','programver','','R','textarea','','R');return document.MM_returnValue">  
 <table>  
<tr>
   <tr>    
     <td colspan="2"><label for="risks" class="vtip" title="Please Enter Comments"><font face=Arial size=2>Comments:</font></label></td>  
     <td colspan="2"> <textarea name="textclient" cols="25" rows="5" tabindex="4" size="50" maxlength="250" STYLE="color: #FFFFFF; font-family: Verdana; font-weight: bold; font-size: 12px; background-color: #72A4D2;"></textarea></td>  
   </tr> 
   <tr>    
     <td colspan="2"><label for="datecreated"><font face=Arial size=2>Upload Date:</font></label></td>  
     <td colspan="2"><label id="uploaddate" STYLE="color: #FFFFFF; font-family: Verdana; font-weight: bold; font-size: 12px; background-color: #72A4D2;"/><?php echo date('Y-m-d');?></label></td>  
   </tr>   
      <tr>    
    [B] <td colspan="2"><label for="browse" class="vtip" title="Please Select the File to be uploaded"><font face=Arial size=2>Attachment:</font></label></td>  
     <td colspan="2">
      <input type="file" name="myfile" tabindex="1" />
       <p><input type="hidden" name="execute" value="1" /></p> 
</td> [/B]

   </tr>
     <tr>    
     <td colspan="4"><input type="submit" name="Submit" value="Submit" tabindex="8" /></td>  
   </tr>  
 </table>  
</form>

this is my upload code:

$file = $_FILES['myfile'];

$allowedExtensions = array("zip", "rar");

function isAllowedExtension($fileName) {
  global $allowedExtensions;

  return in_array(end(explode(".", $fileName)), $allowedExtensions);
}

if($file['error'] == UPLOAD_ERR_OK) {
  if(isAllowedExtension($file['name'])) {
    # Do uploading here
	if (file_exists("scripts/" . $_FILES["myfile"]["name"]))
      {
      echo $_FILES["myfile"]["name"] . " already exists. ";
      }
    else
      {
      move_uploaded_file($_FILES["myfile"]["tmp_name"],
      "scripts/" . $_FILES["myfile"]["name"]);
      echo "Stored in: " . "scripts/" . $_FILES["myfile"]["name"];
      }
  } else {
    echo "Invalid file type";
  }
} else die("Cannot upload");

Please help :'( when i don't the input type=file make a separate form it uploads with the entire form.

Recommended Answers

All 6 Replies

are you set to be using php5?

What version should I have? I have wamp 2 or the recent 1.0 version not sure what version of php. What would you suggest?

Have you checked to see if wamp has all of the functions you need? I had to stop using wamp becuase of these issues.

create a file called info.php and put this code into it (then run it) and it will give you your php version

<?php
phpinfo();
?>

got version 5.3.0

ok its not the version.

When i upload i use the following to determine allowed file types

$_FILES["file"]["type"] == "image/gif"

try fitting that somewhere. you will obviously need to amend the image part

ill keep thinking

this may be helpful, its the whole script i use to upload

<?php

 if (isset($_POST['submit'])){
	 if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/bmp")
|| ($_FILES["file"]["type"] == "image/png")
|| ($_FILES["file"]["type"] == "image/pjpeg"))
&& ($_FILES["file"]["size"] < 100000))
  {
  if ($_FILES["file"]["error"] > 0)
    {
    echo "Return Code: " . $_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 "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";

    if (file_exists($dir . $_FILES["file"]["name"]))
      {
      echo $_FILES["file"]["name"] . " already exists. ";
      }
    else
      {
	
      move_uploaded_file($_FILES["file"]["tmp_name"], $dir . $_FILES["file"]["name"]);
      echo "Stored in: " . $dir . $_FILES["file"]["name"];
      }
    }
  }
else
  {
  echo "<strong><font color=\"#ff0000\">Invalid</font>.";
  }
 }
?>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.