Page 1 of 1

Errors! Where are you when I need you?

Posted: Tue Aug 16, 2005 2:06 am
by harrisonad
Hi, I am currently working on an file upload script and upon filtering the file to upload, the compiler doesnt seem to recognized the following error constants that is from the manual:

Code: Select all

UPLOAD_ERR_NO_TMP_DIR      // Value: 6; Missing a temporary folder.
UPLOAD_ERR_CANT_WRITE      // Value: 7; Failed to write file to disk
Is it version-specific? or I just have to configure something?

I am using PHP 4.4.0

Thanks.

Posted: Tue Aug 16, 2005 2:55 am
by phpdevuk
might want to post a bit more of your code

Posted: Tue Aug 16, 2005 3:09 am
by harrisonad
The errors always says 'undefined constant' whenever I use one of them.

Posted: Tue Aug 16, 2005 3:20 am
by JayBird
harrisonad wrote:The errors always says 'undefined constant' whenever I use one of them.
Still, posting yur code would be helpul

Posted: Tue Aug 16, 2005 3:24 am
by harrisonad
sorry for being stuborn, here it is like

Code: Select all

// ...
}elseif($error==UPLOAD_ERR_NO_TMP_DIR){
	$this->message = "<font color=red><b>Server Error:</b></font><br>A problem occured while upload file. Please try again later.";
	ReportError("Temporay folder used in uploading does not exists. Check PHP.ini");
}elseif($error==UPLOAD_ERR_CANT_WRITE){
	$this->message = "<font color=red><b>Server Error:</b></font><br>A problem occured while upload file. Please try again later.";
	ReportError("Uploading -> Cannot write to hard disk.");
//...
Here it is the error
Notice: Use of undefined constant UPLOAD_ERR_NO_TMP_DIR - assumed 'UPLOAD_ERR_NO_TMP_DIR' in C:\Inetpub\wwwroot\intranet\scripts\reportupdate_inc.php on line 149
Any Idea?

Posted: Tue Aug 16, 2005 4:11 am
by phpdevuk
have you tried putting quotes around the error codes?

Posted: Tue Aug 16, 2005 4:15 am
by harrisonad
phpdevuk wrote:have you tried putting quotes around the error codes?
It will be a string if I do that.

Code: Select all

}elseif($error=="UPLOAD_ERR_NO_TMP_DIR"){
Your suggestion will compare $error ( an integer ) to a string.

Posted: Tue Aug 16, 2005 6:38 am
by feyd
The general discussion board is not for coding problems.


Moved to PHP - Code. :?

Posted: Tue Aug 16, 2005 6:47 am
by phpdevuk
what about just using the numeric values

Posted: Tue Aug 16, 2005 6:47 am
by feyd
file-upload errors wrote:UPLOAD_ERR_NO_TMP_DIR
Value: 6; Missing a temporary folder. Introduced in PHP 4.3.10 and PHP 5.0.3.

UPLOAD_ERR_CANT_WRITE
Value: 7; Failed to write file to disk. Introduced in PHP 5.1.0.
seems pretty straight forward the second one won't exist for you, however the first seems like it should...

you can always use defined() and constant()

Posted: Tue Aug 16, 2005 8:21 pm
by harrisonad
Thanks sir.

Posted: Tue Aug 16, 2005 8:52 pm
by skhale

Code: Select all

// Define Upload Error Constants
	if (!defined('UPLOAD_ERR_OK')) {
		define('UPLOAD_ERR_OK', 0);
		// There is no error, the file uploaded with success.
	}

	if (!defined('UPLOAD_ERR_INI_SIZE')) {
		define('UPLOAD_ERR_INI_SIZE', 1);
		// The uploaded file exceeds the upload_max_filesize directive in php.ini.
	}

	if (!defined('UPLOAD_ERR_FORM_SIZE')) {
		define('UPLOAD_ERR_FORM_SIZE', 2);
		// The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form.
	}

	if (!defined('UPLOAD_ERR_PARTIAL')) {
		define('UPLOAD_ERR_PARTIAL', 3);
		// The uploaded file was only partially uploaded.
	}

	if (!defined('UPLOAD_ERR_NO_FILE')) {
		define('UPLOAD_ERR_NO_FILE', 4);
		// No file was uploaded.
	}

	if (!defined('UPLOAD_ERR_NO_TMP_DIR')) {
		define('UPLOAD_ERR_NO_TMP_DIR', 6);
		// Missing a temporary folder. Introduced in PHP 4.3.10 and PHP 5.0.3.
	}

	if (!defined('UPLOAD_ERR_CANT_WRITE')) {
		define('UPLOAD_ERR_NO_CANT_WRITE', 7);
		// Failed to write file to disk. Introduced in PHP 5.1.0.
	}

Posted: Wed Aug 17, 2005 6:16 am
by bokehman
Where are you getting these constants from? The error info is held in $_FILES['****']['error']

Posted: Wed Aug 17, 2005 7:35 am
by feyd
they're listed in the php manual. If you follow the first link in my last post, you'd find that out.