0

I don't manage to understand why the code below gives me this error: Strict Standards: Only variables should be passed by reference in /web/htdocs/www.mywebsite.com/admin/post/upload.php on line 8

Anyway, the result is successful! (it gives me "Success" and actually works) How could I fix it?

Sorry for my english, thank you in advance!

The line 8 is: $file_ext=strtolower(end(explode('.',$_FILES['image']['name'])));

The whole code is:

<?php
   if(isset($_FILES['image'])){
      $errors= array();
      $file_name = $_FILES['image']['name'];
      $file_size = $_FILES['image']['size'];
      $file_tmp = $_FILES['image']['tmp_name'];
      $file_type = $_FILES['image']['type'];
      $file_ext=strtolower(end(explode('.',$_FILES['image']['name'])));

      $expensions= array("jpeg","jpg","png","pdf");

      if(in_array($file_ext,$expensions)=== false){
         $errors[]="Error. Supported formats: JPG, JPEG, PNG, PDF";
      }

      if($file_size > 999999999) {
         $errors[]='File too large';
      }

      if(empty($errors)==true) {
         move_uploaded_file($file_tmp,"../../../sources/".$file_name);
         echo "Success";
      }else{
         print_r($errors);
      }
   }
?>
<html>
   <body>

      <form action = "" method = "POST" enctype = "multipart/form-data">
         <input type = "file" name = "image" />
         <input type = "submit"/>

         <ul>
            <li>Filename: /press/sources/<?php echo $_FILES['image']['name'];  ?>
            <li>Size: <?php echo $_FILES['image']['size'];  ?>
            <li>Format: <?php echo $_FILES['image']['type'] ?>
         </ul>

      </form>

   </body>
</html>
alberto96
  • 1
  • 3
  • Check out the docs. http://php.net/manual/en/function.end.php The discussion there even has a helper function that will fix hti sissue. – CollinD Oct 27 '16 at 17:05
  • Either by splitting your 8th line into 2 lines using an intermeiate variable; or by using PHP's built-in [pathinfo()](http://nl1.php.net/manual/en/function.pathinfo.php) function to get the file extension – Mark Baker Oct 27 '16 at 17:07
  • sorry, the question was already answered other times but this is a specific case and I don't know PHP very well. – alberto96 Oct 27 '16 at 17:07

0 Answers0