dale1991
10-20-2006, 04:09 PM
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?
/**
* 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 :)
maxymizer
10-20-2006, 04:20 PM
/**
* 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;
}
}
horizon
10-20-2006, 05:09 PM
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:
public function CheckFileSize($file)
{
highly recommended to add :
$file = (isset($file)) ? basename(stripslashes(trim($file))) : "";
Then, change:
if($this->max_file_size < filesize($_FILES[$file]['size'])) // line 68!
{
for:
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 ! ;)
maxymizer
10-20-2006, 06:47 PM
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.
$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:
public function CheckFileSize($file = null)
{
if(is_null($file)) { // report error }
}
;)
horizon
10-20-2006, 06:53 PM
public function CheckFileSize($file = null)
{
if(is_null($file)) { // report error }
}
Yes, this function is indeed correct. ;)
maxymizer
10-20-2006, 07:50 PM
It's called programming method, mr. syntax error. ;)