Jump to content

Upload File


hasek522

Recommended Posts

Hi so i am trying to create a file uploader (specifically pictures).  I am encountering some errors.  If any one could help I would appreciate it. 

 

$_FILES['userfile'] is always coming up as being empty. 

 

Here is the HTML form:

 

<form action="action/uploadpicaction.php" method="post">

<input name="userfile" type="file" /> <br  />

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

</form>

 

the php:

 

$allowed_filetypes = array('.jpg','.gif','.bmp','.png','.jpeg'); // These will be the types of file that will pass the validation.

      $max_filesize = 6992347; // Maximum filesize in BYTES (currently 5MB).

      $upload_path = 'userimages/'; // The place the files will be uploaded to (currently a 'files' directory).

 

  $filename = $_FILES['userfile']['name']; // Get the name of the file (including file extension).

  $ext = substr($filename, strpos($filename,'.'), strlen($filename)-1); // Get the extension from the filename.

echo '<h1>'. $_FILES['userfile'].' </h1>';

  // Check if the filetype is allowed, if not DIE and inform the user.

  if(!in_array($ext,$allowed_filetypes))

      die('The file you attempted to upload is not allowed.');

 

  // Now check the filesize, if it is too large then DIE and inform the user.

  if(filesize($_FILES['userfile']['tmp_name']) > $max_filesize)

      die('The file you attempted to upload is too large.');

 

 

Link to comment
https://forums.phpfreaks.com/topic/119388-upload-file/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.