Errors! Where are you when I need you?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
harrisonad
Forum Contributor
Posts: 288
Joined: Fri Oct 15, 2004 4:58 am
Location: Philippines
Contact:

Errors! Where are you when I need you?

Post 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.
User avatar
phpdevuk
Forum Contributor
Posts: 220
Joined: Mon Jul 04, 2005 5:31 am
Location: UK
Contact:

Post by phpdevuk »

might want to post a bit more of your code
User avatar
harrisonad
Forum Contributor
Posts: 288
Joined: Fri Oct 15, 2004 4:58 am
Location: Philippines
Contact:

Post by harrisonad »

The errors always says 'undefined constant' whenever I use one of them.
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

harrisonad wrote:The errors always says 'undefined constant' whenever I use one of them.
Still, posting yur code would be helpul
User avatar
harrisonad
Forum Contributor
Posts: 288
Joined: Fri Oct 15, 2004 4:58 am
Location: Philippines
Contact:

Post 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?
User avatar
phpdevuk
Forum Contributor
Posts: 220
Joined: Mon Jul 04, 2005 5:31 am
Location: UK
Contact:

Post by phpdevuk »

have you tried putting quotes around the error codes?
User avatar
harrisonad
Forum Contributor
Posts: 288
Joined: Fri Oct 15, 2004 4:58 am
Location: Philippines
Contact:

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

The general discussion board is not for coding problems.


Moved to PHP - Code. :?
User avatar
phpdevuk
Forum Contributor
Posts: 220
Joined: Mon Jul 04, 2005 5:31 am
Location: UK
Contact:

Post by phpdevuk »

what about just using the numeric values
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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()
User avatar
harrisonad
Forum Contributor
Posts: 288
Joined: Fri Oct 15, 2004 4:58 am
Location: Philippines
Contact:

Post by harrisonad »

Thanks sir.
skhale
Forum Newbie
Posts: 6
Joined: Sat Aug 06, 2005 12:56 pm
Location: Boston, MA

Post 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.
	}
User avatar
bokehman
Forum Regular
Posts: 509
Joined: Wed May 11, 2005 2:33 am
Location: Alicante (Spain)

Post by bokehman »

Where are you getting these constants from? The error info is held in $_FILES['****']['error']
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

they're listed in the php manual. If you follow the first link in my last post, you'd find that out.
Post Reply