Jump to content

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

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.