php - Dynamically created directory returns "Array" 1 in 1000 times -
i'm fixing old code supposed create directory customer based on customer's last name. 999 out of 1000 times works expected every , "unable create base directory" error message , debug shows me $file_directory
in case "array"
instead of "\\network\path\order_data\1234567890_smith"
.
could explain how code work vast majority of time still consistently fail .1% of instances? or other code? thanks!
note: did not write code tring leave close original possible
edit had typo in previous code think tliokos , fluinc had point wanted fix mistake
code:
<?php $file_directory = build_directory($customer, $uid); if(!is_dir($file_directory)){ //check make sure not exist if(!mkdir($file_directory)){ mail("debug@example.com","unable create base directory","$file_directory"); } } function build_directory($customer, $uid){ if($customer->related_orders){ $related = explode(",", $customer->related_orders); foreach($related $r_uid){ $rel_order = get_order($r_uid); //fetches order object if((isset($rel_order->file_directory) && $rel_order->file_directory != "")){ return $rel_order->file_directory; } } } //here made correction $paths = array('\\\\network\\path'); $base = $paths[0]; //test if directory assigned if(is_dir($base . "\\order_data\\".$uid."_".str_replace(" ","_",$customer->last_name)."\\")){ return $base . "\\order_data\\".$uid."_".str_replace(" ","_",$customer->last_name)."\\"; } if($base){ return $base . "\\order_data\\".$uid."_".str_replace(" ","_",$customer->last_name)."\\"; } } ?>
change $base = array('\\network\path');
$base = '\\network\path';
Comments
Post a Comment