Results 1 to 7 of 7
Thread: Array to string conversion
-
10-20-2006, 04:09 PM #1WHT Addict
- 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;
}
}
$file contains the name for the file that is being checked!
Thanks,
- Dale
-
10-20-2006, 04:20 PM #2Web Hosting Evangelist
- Join Date
- Apr 2005
- Posts
- 522
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;
}
}
-
10-20-2006, 04:49 PM #3WHT Addict
- Join Date
- Mar 2006
- Location
- London, UK
- Posts
- 125
esactly the same error.
-
10-20-2006, 05:09 PM #4Web Hosting Master
- 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)
{
PHP Code:$file = (isset($file)) ? basename(stripslashes(trim($file))) : "";
Then, change:
PHP Code:if($this->max_file_size < filesize($_FILES[$file]['size'])) // line 68!
{
PHP Code:if($this->max_file_size < filesize($_FILES[$file]['size']) || empty($file)) // line 68!
{
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.
-
10-20-2006, 06:47 PM #5Web Hosting Evangelist
- Join Date
- Apr 2005
- Posts
- 522
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))) : "";
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 }
}
-
10-20-2006, 06:53 PM #6Web Hosting Master
- Join Date
- Mar 2006
- Posts
- 984
PHP Code:public function CheckFileSize($file = null)
{
if(is_null($file)) { // report error }
}
-
10-20-2006, 07:50 PM #7Web Hosting Evangelist
- Join Date
- Apr 2005
- Posts
- 522
It's called programming method, mr. syntax error.