Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    May 2011
    Posts
    303
    Thanks
    29
    Thanked 0 Times in 0 Posts

    uploaded imags dont have extensions?

    Anyone can say why my images upload with no extension:
    PHP Code:
    <?php
        
    include $_SERVER['DOCUMENT_ROOT'] .'/includes/init.php';
        
        
    $tFiles $_FILES['image_upload']['tmp_name'];
        
    print_r($_FILES);
        
        for(
    $i 0$i count($tFiles); ++$i)
        {
            
    performaLocalUpload($_FILES['image_upload']['tmp_name'][$i], $uploadDir$allowed$maxfileSize);
        }

            function 
    performaLocalUpload($files$uploadDir$allowed$maxfileSize)
            {
                
    $oName                         $_FILES['image_upload']['name'][$i];
                
    $mType                         $_FILES['image_upload']['type'][$i];
                
    $fSize                         $_FILES['image_upload']['size'][$i];
                
                
    $ext substr($oNamestrrpos($oName'.')); // grab file extension.
                
    $ext strtolower($ext); // get the extension of the file in a lower case format.
                
                
    $errors = array();
                
                
    // Do checks of the files.
                
    if(in_array($mType$allowed))
                {
                    
    $errors[] = 'File type is not allowed.';
                }
                
                if(
    $fSize $maxfileSize)
                {
                    
    $errors[] = 'Max file size is 4mb.';
                }
                
                if(!empty(
    $errors))
                {
                    foreach(
    $errors as $error)
                    {
                        echo 
    $error .'<br>';
                    }
                } else {
                    
                    
    $new_name gen_uniqueFilename().$ext//we will give an unique name.
                    
    $uploadFilePath $uploadDir .'/'$new_name;
                    
                    if (!
    move_uploaded_file($files$uploadFilePath)) {
                        
    trigger_error('Failed to upload image');
                    }
                }
            }
    ?>
    Thanks

  • #2
    Senior Coder
    Join Date
    Sep 2010
    Posts
    1,978
    Thanks
    15
    Thanked 229 Times in 229 Posts
    You have a statement for 'not move_uploaded_file' but you don't have one for 'move_uploaded_file' so I don't think the uploaded file is even being sent to the folder. If you're going to rename the file anyway it's much easier to get the extension from the ['type'] data by using basename, and it's already lower case. But you're getting there. Make use of the data in the print_r statement since php already knows it.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •