if(in_array($file_ext, $ext_arr['image'])) $file_path='uploads/image/'.$new_file_name;if(in_array($file_ext, $ext_arr['media'])) $file_path='uploads/media/'.$new_file_name;if(in_array($file_ext, $ext_arr['file'])) $file_path='uploads/file/'.$new_file_name;
Let's see how the code above is streamlined.
Reply content:
if(in_array($file_ext, $ext_arr['image'])) $file_path='uploads/image/'.$new_file_name;if(in_array($file_ext, $ext_arr['media'])) $file_path='uploads/media/'.$new_file_name;if(in_array($file_ext, $ext_arr['file'])) $file_path='uploads/file/'.$new_file_name;
Let's see how the code above is streamlined.
Put the $ext_arr
ban on, change it to
$types_of_extensions = array( 'jpg' => 'image', 'png' => 'image', 'gif' => 'image', 'rmvb' => 'media', 'mp3' => 'media', 'doc' => 'file', 'pptx' => 'file' /* ... and many more, whatever u want */);$file_path = 'uploads/' . $types_of_extensions[$file_ext] . '/' . $new_file_name;
foreach(array('image', 'media', 'file') as $type) foreach($ext_arr[$type] as $t) @$ext[$t] = $type;$file_path = "uploads/{$ext[$file_ext]}/$new_file_name";
Just to talk about streamlining, the success of streamlining three lines of the look and the number of words are much less, two lines look more ugly I will not shrink ~
Streamlining can not be optimized on the process
if(in_array($file_ext, $ext_arr['image'])) $file_path='uploads/image/'.$new_file_name; elseif(in_array($file_ext, $ext_arr['media'])) $file_path='uploads/media/'.$new_file_name; elseif(in_array($file_ext, $ext_arr['file'])) $file_path='uploads/file/'.$new_file_name;
foreach (array('image', 'media', 'file') as $type) { if(in_array($file_ext, $ext_arr[$type])){ $file_path="uploads/$type/$new_file_name"; break; }}
This code highlighting does not support the highlighting of the string interpolation in PHP ...