Results 1 to 7 of 7
  1. #1
    Join Date
    Mar 2006
    Location
    London, UK
    Posts
    125

    Array to string conversion

    Hello,
    I keep getting an Array to string conversion error on line 68 could anyone please tell me what it means and how to fix it?

    PHP Code:
    /**
         * Get the size in kb of the file and
         * prints an error is it exceed max_file_size 
         *
         * @param string $file
         */
        
    public function CheckFileSize($file)
        {
            if(
    $this->max_file_size <  filesize($_FILES[$file]['size'])) // line 68!
            
    {
                
    $this->errors[] = "Your File: ".$_FILES[$file]["name"]." is "
                
    .filesize($_FILES[$file])." KB, the max file size allowed  is "
                
    .$this->max_file_size;
            }
        } 
    NOTE:
    $file contains the name for the file that is being checked!


    Thanks,
    - Dale

  2. #2
    PHP Code:
    /**
         * Get the size in kb of the file and
         * prints an error is it exceed max_file_size 
         *
         * @param string $file
         */
        
    public function CheckFileSize($file)
        {
            if(
    $this->max_file_size <  filesize($_FILES[$file]['size'])) // line 68!
            
    {
                
    $this->errors[] = "Your File: ".$_FILES[$file]["name"]." is "
                
    .filesize($_FILES[$file]['tmp_name'])." KB, the max file size allowed  is "
                
    .$this->max_file_size;
            }
        } 

  3. #3
    Join Date
    Mar 2006
    Location
    London, UK
    Posts
    125
    esactly the same error.

  4. #4
    Join Date
    Mar 2006
    Posts
    984
    Did you specified an equality for this->max_file_size above your public function block ?

    Also, did you specify an equality to specify an array for your $this->errors above that block ?

    Then, below this line:

    PHP Code:
    public function CheckFileSize($file

    highly recommended to add :

    PHP Code:
    $file = (isset($file)) ? basename(stripslashes(trim($file))) : ""


    Then, change:

    PHP Code:
    if($this->max_file_size filesize($_FILES[$file]['size'])) // line 68! 

    for:

    PHP Code:
    if($this->max_file_size filesize($_FILES[$file]['size']) || empty($file)) // line 68! 

    In the mean time, I would also suggest using a tmp_name (stands for: temp file name) during the upload process in case the operation fails. It will be far less difficult for you to see what might be the source of the problem during the temp upload process since you could specify if the tmp name equals to none.

    If it does succeeds though, you could, in the mean time, use the @move_uploaded_file based function (suggest to equal it under a $this-> variable) into it's original path location then tala !
    Last edited by horizon; 10-20-2006 at 05:14 PM.

  5. #5
    I just noticed your line 68 -> under $_FILES[$file]['size'], you have stored filesize of your file. There's no need to add filesize($_FILES[$file]['size']).

    Horizon, your "recommendation" is again wrong.
    PHP Code:
    $file = (isset($file)) ? basename(stripslashes(trim($file))) : ""
    If you don't pass a parameter to the function, an error will be reported. No need to check if $file is set within a function.

    Sanity check should be done by specifying a default value for function parameter:

    PHP Code:
    public function CheckFileSize($file null)
    {
        if(
    is_null($file)) { // report error }


  6. #6
    Join Date
    Mar 2006
    Posts
    984
    PHP Code:
    public function CheckFileSize($file null)
    {
        if(
    is_null($file)) { // report error }

    Yes, this function is indeed correct.

  7. #7
    It's called programming method, mr. syntax error.

Posting Permissions

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