Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3489062
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T11:20:50+00:00 2026-05-18T11:20:50+00:00

The code <?php $allowed_filetypes = array(‘.jpg’,’.gif’,’.bmp’,’.png’); $max_filesize = 5242888; $upload_path = ‘/files’; $filename =$_FILES[‘userfile’][‘name’];

  • 0

The code

<?php
    $allowed_filetypes = array('.jpg','.gif','.bmp','.png');
    $max_filesize = 5242888;
    $upload_path = '/files';
    $filename =$_FILES['userfile']['name'];
    $ext = substr($filename,strpos($filename,'.'),strlen($filename)-1); //Get the     extension form the filename.

    if(!in_array($ext,$allowed_filetypes))
        die('the file you attempted to upload is not allowed.');

    if(filesize($_FILES['userfile']['size'])>$max_filesize)
        die('the file you attempted to upload is too large.');

    if(!is_writable($upload_path)) {
        die('you cannot upload to the specified directory,please CHMOD it to 777.');
    }

    if (move_uploaded_file( $_FILES['userfile']['tmp_name'],$upload_path.$filename))
    {
        echo 'you file upload successful.view the file <a      href=".$upload_path.$filename.title="your file">here</a>';
    }
    else{
        echo 'failed';
    }

When I upload a JPEG image, it shows the error “The file you attempted to upload is not allowed.”. What’s wrong with my code?

The main HTML code:

<form action="upload.php" method="post" enctype="multipart/form-data">
    <input type="file" name="userfile" id="file"/>
    <button>upload</button>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T11:20:51+00:00Added an answer on May 18, 2026 at 11:20 am

    Try replace:

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

    by

    $ext = substr($filename,strpos($filename,'.'),4);
    //get the     extension form the filename 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The following PHP code snippet uses GD to resize a browser-uploaded PNG to 128x128.
I want to upload .3gp video files to server via PHP code. I checked
At the moment my code (PHP) has too many SQL queries in it. eg...
This PHP code... 207 if (getenv(HTTP_X_FORWARDED_FOR)) { 208 $ip = getenv('HTTP_X_FORWARD_FOR'); 209 $host =
Optimization of PHP code via runtime benchmarking is straight forward. Keep track of $start
I am writing PHP code where I want to pass the session id myself
I wrote a PHP code like this $site=http://www.google.com; $content = file_get_content($site); echo $content; But
I have this php code, with which I am trying to generate a popup
I have this PHP code echo '<a href=# onclick=updateByQuery(\'Layer3\', ' . json_encode($query) . ');>Link
I have inherited some legacy PHP code what was written back when it was

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.