Search code examples
phpfile-uploaduploadinternal-server-errorphp-5.5

error 500 in php when upload is complete


<?php
error_reporting(E_ALL);
ini_set('display_errors', 'on');
if(isset($_FILES['userfile']){
$file = $_FILES['userfile'];

//proprietà del file

$file_name = $file['name'];
$file_tmp = $file['tmp_name'];
$file_size = $file['size'];
$file_error = $file['error'];

// come gestire il file

$file_ext = explode(".",$file_name);
$file_ext = strtolower(end($file_ext));

$allowed = array("txt", "jpg", "csv");
// controlli vari
if ($file_ext, $allowed){
  if($file_error === 0){
    if($file_size <= 2097152){
        print_r($file_size);
      $file_name_new = uniqid("", true) . "." . $file_ext;
      $file_destination = "uploads/" . $file_name_new;

      if(move_uploaded_file($file_tmp, $file_destination)){
        echo $file_destination;
        }
      }
    }
  }



}


 ?>

Hi, the problem is when i try to upload 1 file any dimension when upload end , show error 500 i think there is an error in the code pls can you ceck this code for error ?

p.s i have changed this parameter:

post_max_size  64M
upload_max_filesize 64M
max_input_time 3000
max_execution_time 3000

but nothing is happen

update: thanks for all reply tryed to running php -l file-name.php and i have corrected the error but now when i upload the file i have white screen after upload done.


Solution

  • Change

    if ($file_ext, $allowed)
    

    to

    if (in_array($file_ext, $allowed))
    

    For other errors, try running php -l file-name.php to show you some other things which may be wrong with the syntax