if (is_dir($sub_dir)) { echo str_repeat('-', $lv) . $file . "\n"; test1($sub_dir, $lv + 1); } else { echo str_repeat('-', $lv) . $file . "\n"; } } } } //test1('./g'); //图片转成base64并保存 function pic($path) { is_file($path) or die('is not file'); $file_info = getimagesize($path); $file_type = $file_info['mime']; //var_export($file_info); $file_content = file_get_contents($path); $base64_header = 'data:' . $file_type . ';base64,'; $file_base64 = $base64_header . chunk_split(base64_encode($file_content)); echo '<img src="' . $file_base64 . '">'; $new_name = dirname($path) . '/new' . substr($path, strrpos($path, '.')); $preg = '/^data:(\\w+)\\/\\w+;base64,(.*)/'; preg_match($preg, $file_base64, $get_arr); //var_export($get_arr); file_put_contents($new_name, base64_decode($get_arr[2])); //文件的绝对路径 echo realpath($new_name); } pic('./g/1.jpg');
<body> <div id = 'wrapper'> <?php headerAndSearchCode(); ?> <aside id = 'left_side'> <?php IndexCategoryList(); ?> </aside> <section id = 'right_side1'> <section id = 'right_side11'> <?php pic(); ?> <section id = 'right_side12'> <?php basic_info(); ?> </section> </section> <section id = 'right_side13'> <?php description(); ?> </section> <?php