freakus_maximus Posted August 8, 2007 Share Posted August 8, 2007 I have this bit of code that is checking free/used space on a network server. As long as I have permissions I get a valid response. However, if I don't have access or the path is not correct I get a hard error that the network path was not found: Warning: disk_total_space() [function.disk-total-space]: The network path was not found. in C:\xampp\xampp\htdocs\test\dir\drivespace2.php on line 5 Warning: disk_free_space() [function.disk-free-space]: The network path was not found. in C:\xampp\xampp\htdocs\test\dir\drivespace2.php on line 7 Warning: Division by zero in C:\xampp\xampp\htdocs\test\dir\drivespace2.php on line 10 Warning: Division by zero in C:\xampp\xampp\htdocs\test\dir\drivespace2.php on line 11 I would like to provide a soft error back that indicates that the problem is either permissions or the network path is not valid instead of the hard error above. Here's the snippet: define("DISK","//netserver/apps/"); $total = round(disk_total_space(DISK)/1024/1024,2); $free = round(disk_free_space(DISK)/1024/1024,2); $used = $total - $free; $used = round(($used/$total)*100); $free = round(($free/$total)*100); if ($free < 10) { //echo ("Bad"); echo (DISK. " " .'<img src="red.png" alt="There is less than '. $free .'% free space at '. DISK .' Attention Required!">'); } else { //echo ("Good"); echo (DISK. ' ' .'<img src="green.png" alt="There is '. $free .'% free space at '. DISK .'">'); } Any ideas? Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/63946-solved-soft-error-vs-hard-error/ Share on other sites More sharing options...
akitchin Posted August 8, 2007 Share Posted August 8, 2007 you could probably get around the warning by suppressing the error using the @ operator, and then checking the return value. you'd want to add an if() statement to avoid the division by zero operation if you have no permission to access the path. Quote Link to comment https://forums.phpfreaks.com/topic/63946-solved-soft-error-vs-hard-error/#findComment-318746 Share on other sites More sharing options...
lemmin Posted August 8, 2007 Share Posted August 8, 2007 Using @ and die would give you a simple universal error for path not found AND bad permissions, but you couldn't discern between the two. I might be wrong, but I don't think that php even looks at permissions. It simply can or cannot access the path, whether it is because it doesn't have permissions or the path doesn't exist isn't even looked at. I know that there are functions that allow you to look at the permissions of a file or folder, but I doubt that would work if you don't have access to them. Quote Link to comment https://forums.phpfreaks.com/topic/63946-solved-soft-error-vs-hard-error/#findComment-318751 Share on other sites More sharing options...
freakus_maximus Posted August 8, 2007 Author Share Posted August 8, 2007 Thanks for the info, I am using the @ operator and a "or print" option which works nicely. I also added an IF to handle the division by zero. $total = @round(disk_total_space(DISK)/1024/1024,2) or print '<img src="grey.png" alt="'.DISK.' is not accessible.">'; Quote Link to comment https://forums.phpfreaks.com/topic/63946-solved-soft-error-vs-hard-error/#findComment-318803 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.