Database Storage
CMU Database System 15-445/645 储存 Part 1 数据库存储的数据在 FS(File System) 中是以 块(Block) 的方式表示的. 实际上你很可能已经见到过了,在MySQL中的数据库就是以一切Block文件的方式存储的. 这篇文章会告诉你目前常见的数据库存储方式. 最开始用Tuple Storage来尝试改善数据库的存储结构. ...
CMU Database System 15-445/645 储存 Part 1 数据库存储的数据在 FS(File System) 中是以 块(Block) 的方式表示的. 实际上你很可能已经见到过了,在MySQL中的数据库就是以一切Block文件的方式存储的. 这篇文章会告诉你目前常见的数据库存储方式. 最开始用Tuple Storage来尝试改善数据库的存储结构. ...
半年前在研究HashMap的时候已经学习过红黑树的规则原理了. 不过现在又遇到就忘记是怎么实现的了.(只知道这玩意是用来平衡树的) 这次就把这个数据结构做一个了断. 性质 性质1:每个节点要么是黑色,要么是红色。 性质2:根节点是黑色。 性质3:每个叶子节点(NIL)是黑色。 性质4:每个红色结点的两个子结点一定都是黑色。 性质5:任意一结点到每个叶子结点的路径都包含数量相同的黑结点。 满足这5个性质就能保证红黑树是平衡的. ...
这是 MIT 6.824 课程GFS部分的一些总结. GFS (Google File System) 是Google为了管理海量数据而开发的一个分布式文件系统. 直接进入正题. 在GFS中文件是以Chunk的形式存储。所谓的Chunk是一个储存块。一个Chunk的大小为64MB.一个文件会分为多个Chunk.储存在不同的服务器里。当然也会有2-3份Chunk的拷贝。 ...
第一代分布式系统采用的是中心化的系统,对于存贮大量数据的分布式系统来说它的缺点就是中央节点成为了整个个分布式系统的单点故障. 第二代分布式系统,节点之间通行采用的是广播,每个节点都向自己相连的所有节点进行询问,被询问的节点如果不知道这个文件在哪里,就再次进行广播……如此往复,直至找到所需文件。请求变多就意味着会产生广播风暴,这会严重占用带宽和系统资源。 ...
LOW 1if( isset( $_POST[ 'Submit' ] ) ) { 2 // Get input 3 $target = $_REQUEST[ 'ip' ]; 4 5 // 没有任何过滤 6 // 直接运行 ping $param 7 8 // 可以尝试运行各种奇怪的命令组合 9 // 输入 localhost && ls 10 11 // Determine OS and execute the ping command. 12 if( stristr( php_uname( 's' ), 'Windows NT' ) ) { 13 // Windows 14 $cmd = shell_exec( 'ping ' . $target ); 15 } 16 else { 17 // *nix 18 $cmd = shell_exec( 'ping -c 4 ' . $target ); 19 } 20 21 // Feedback for the end user 22 echo "<pre>{$cmd}</pre>"; 23} Medium 1if( isset( $_POST[ 'Submit' ] ) ) { 2 // Get input 3 $target = $_REQUEST[ 'ip' ]; 4 5 // Set blacklist 6 // 黑名单式过滤 7 $substitutions = array( 8 '&&' => '', 9 ';' => '', 10 ); 11 12 // 然而过滤的并不严谨 13 // 使用 localHost &&& ls 14 // 或者管道?(Linux) 15 // localhost | ls` 16 17 // Remove any of the charactars in the array (blacklist). 18 $target = str_replace( array_keys( $substitutions ), $substitutions, $target ); 19 20 // Determine OS and execute the ping command. 21 if( stristr( php_uname( 's' ), 'Windows NT' ) ) { 22 // Windows 23 $cmd = shell_exec( 'ping ' . $target ); 24 } 25 else { 26 // *nix 27 $cmd = shell_exec( 'ping -c 4 ' . $target ); 28 } 29 30 // Feedback for the end user 31 echo "<pre>{$cmd}</pre>"; 32} High 1if( isset( $_POST[ 'Submit' ] ) ) { 2 // Get input 3 $target = trim($_REQUEST[ 'ip' ]); 4 5 // 过滤的更猛了 6 // Set blacklist 7 $substitutions = array( 8 '&' => '', 9 ';' => '', 10 '| ' => '', 11 '-' => '', 12 '$' => '', 13 '(' => '', 14 ')' => '', 15 '`' => '', 16 '||' => '', 17 ); 18 19 // 然而只过滤一遍 20 // localhost |||| 21 22 // Remove any of the charactars in the array (blacklist). 23 $target = str_replace( array_keys( $substitutions ), $substitutions, $target ); 24 25 // Determine OS and execute the ping command. 26 if( stristr( php_uname( 's' ), 'Windows NT' ) ) { 27 // Windows 28 $cmd = shell_exec( 'ping ' . $target ); 29 } 30 else { 31 // *nix 32 $cmd = shell_exec( 'ping -c 4 ' . $target ); 33 } 34 35 // Feedback for the end user 36 echo "<pre>{$cmd}</pre>"; 37}
是一种SSRF漏洞 Low 1// 非常单纯, 随便读取 2// http://192.168.32.114/vulnerabilities/fi/?page=../../../../../../etc/passwd 3// The page we wish to display 4$file = $_GET[ 'page' ]; Medium 1// The page we wish to display 2$file = $_GET[ 'page' ]; 3 4// 过滤一部分字符 5// 不允许 HTTP,HTTPS 协议 6// 利用目录结构读取也不行 7 8// 然而没有过滤全 9// http://192.168.32.114/vulnerabilities/fi/?page=/etc/passwd 10 11// Input validation 12$file = str_replace( array( "http://", "https://" ), "", $file ); 13$file = str_replace( array( "../", "..\"" ), "", $file ); High 1// The page we wish to display 2$file = $_GET[ 'page' ]; 3 4// Input validation 5// 对$file 字符串做匹配 6// 只能匹配 file* 的文件路径 7// 还有 include.php 文件路径 8 9// 这个过滤还是八星 10// 利用`本地文件传输协议` 11// http://192.168.32.114/vulnerabilities/fi/?page=file:///etc/passwd 12 13// 或者这样 14// http://192.168.32.114/vulnerabilities/fi/?page=file123123/../../../../../../etc/passwd 15 16if( !fnmatch( "file*", $file ) && $file != "include.php" ) { 17 // This isn't the page we want! 18 echo "ERROR: File not found!"; 19 exit; 20} Impossible 1// The page we wish to display 2$file = $_GET[ 'page' ]; 3 4// Only allow include.php or file{1..3}.php 5// 强匹配 6// 从程序员的角度来说这种代码的维护性极差 7// 从安全的角度上来说这是最安全的方案 8if( $file != "include.php" && $file != "file1.php" && $file != "file2.php" && $file != "file3.php" ) { 9 // This isn't the page we want! 10 echo "ERROR: File not found!"; 11 exit; 12}
LOW 1if( isset( $_POST[ 'Upload' ] ) ) { 2 // Where are we going to be writing to? 3 $target_path = DVWA_WEB_PAGE_TO_ROOT . "hackable/uploads/"; 4 $target_path .= basename( $_FILES[ 'uploaded' ][ 'name' ] ); 5 6 // Can we move the file to the upload folder? 7 // 完全没做过滤. 8 // 上传一个PHP文件也是可以的. 9 if( !move_uploaded_file( $_FILES[ 'uploaded' ][ 'tmp_name' ], $target_path ) ) { 10 // No 11 echo '<pre>Your image was not uploaded.</pre>'; 12 } 13 else { 14 // Yes! 15 echo "<pre>{$target_path} succesfully uploaded!</pre>"; 16 } 17} Medium 1if( isset( $_POST[ 'Upload' ] ) ) { 2 // Where are we going to be writing to? 3 $target_path = DVWA_WEB_PAGE_TO_ROOT . "hackable/uploads/"; 4 $target_path .= basename( $_FILES[ 'uploaded' ][ 'name' ] ); 5 6 // File information 7 $uploaded_name = $_FILES[ 'uploaded' ][ 'name' ]; 8 $uploaded_type = $_FILES[ 'uploaded' ][ 'type' ]; 9 $uploaded_size = $_FILES[ 'uploaded' ][ 'size' ]; 10 11 // Is it an image? 12 // // 开始做了一些过滤 13 14 // 下面是官方对$_FILES 函数的描述 15 // [name] => MyFile.txt (comes from the browser, so treat as tainted) 16 // [type] => text/plain (not sure where it gets this from - assume the browser, so treat as tainted) 17 // [tmp_name] => /tmp/php/php1h4j1o (could be anywhere on your system, depending on your config settings, but the user has no control, so this isn't tainted) 18 // [error] => UPLOAD_ERR_OK (= 0) 19 // [size] => 123 (the size in bytes) 20 21 // 其中对name和type的description的描述都是 `treat as tainted`(被污染的) 22 // 这意味着它有可能会被修改 unsafe 23 24 // 我们可以尝试上传一个PHP文件,使用一些拦截请求工具,修改即将发出的请求. 25 // 来达到修改`name`中的后缀名和`type`中的媒体类型. 26 if( ( $uploaded_type == "image/jpeg" || $uploaded_type == "image/png" ) && 27 ( $uploaded_size < 100000 ) ) { 28 29 // Can we move the file to the upload folder? 30 if( !move_uploaded_file( $_FILES[ 'uploaded' ][ 'tmp_name' ], $target_path ) ) { 31 // No 32 echo '<pre>Your image was not uploaded.</pre>'; 33 } 34 else { 35 // Yes! 36 echo "<pre>{$target_path} succesfully uploaded!</pre>"; 37 } 38 } 39 else { 40 // Invalid file 41 echo '<pre>Your image was not uploaded. We can only accept JPEG or PNG images.</pre>'; 42 } 43} High 1if( isset( $_POST[ 'Upload' ] ) ) { 2 // Where are we going to be writing to? 3 $target_path = DVWA_WEB_PAGE_TO_ROOT . "hackable/uploads/"; 4 $target_path .= basename( $_FILES[ 'uploaded' ][ 'name' ] ); 5 6 // File information 7 $uploaded_name = $_FILES[ 'uploaded' ][ 'name' ]; 8 // jpg 9 $uploaded_ext = substr( $uploaded_name, strrpos( $uploaded_name, '.' ) + 1); 10 11 // file size 12 $uploaded_size = $_FILES[ 'uploaded' ][ 'size' ]; 13 14 // tmp_name 是临时副本的名字 15 $uploaded_tmp = $_FILES[ 'uploaded' ][ 'tmp_name' ]; 16 17 // Is it an image? 18 // 和上面的比起来多个一个文件后缀名的判断. 19 // strtolower 转小写 20 // 扩展名只要满足jpeg,png或者jpg就行 21 if( ( strtolower( $uploaded_ext ) == "jpg" || strtolower( $uploaded_ext ) == "jpeg" || strtolower( $uploaded_ext ) == "png" ) && 22 ( $uploaded_size < 100000 ) && 23 // getimagesize 获取图像信息 24 // 这个函数保证你穿的一定得是个图像 25 // 可以用图片木马绕过 26 getimagesize( $uploaded_tmp ) ) { 27 28 // Can we move the file to the upload folder? 29 if( !move_uploaded_file( $uploaded_tmp, $target_path ) ) { 30 // No 31 echo '<pre>Your image was not uploaded.</pre>'; 32 } 33 else { 34 // Yes! 35 echo "<pre>{$target_path} succesfully uploaded!</pre>"; 36 } 37 } 38 else { 39 // Invalid file 40 echo '<pre>Your image was not uploaded. We can only accept JPEG or PNG images.</pre>'; 41 } 42} High 1if( isset( $_POST[ 'Upload' ] ) ) { 2 // Where are we going to be writing to? 3 $target_path = DVWA_WEB_PAGE_TO_ROOT . "hackable/uploads/"; 4 $target_path .= basename( $_FILES[ 'uploaded' ][ 'name' ] ); 5 6 // File information 7 $uploaded_name = $_FILES[ 'uploaded' ][ 'name' ]; 8 $uploaded_ext = substr( $uploaded_name, strrpos( $uploaded_name, '.' ) + 1); 9 $uploaded_size = $_FILES[ 'uploaded' ][ 'size' ]; 10 $uploaded_tmp = $_FILES[ 'uploaded' ][ 'tmp_name' ]; 11 12 // Is it an image? 13 // 对比上面多验证了文件的后缀名 14 if( ( strtolower( $uploaded_ext ) == "jpg" || strtolower( $uploaded_ext ) == "jpeg" || strtolower( $uploaded_ext ) == "png" ) && 15 ( $uploaded_size < 100000 ) && 16 17 // 函数会通过读取文件头,返回图片的长、宽等信息,如果没有相关的图片文件头,函数会报错 18 getimagesize( $uploaded_tmp ) ) { 19 20 // 可以看到,High级别的代码读取文件名中最后一个”.”后的字符串,期望通过文件名来限制文件类型 21 // 因此要求上传文件名形式必须是”*.jpg”、”*.jpeg” 、”*.png”之一 22 // 同时,getimagesize函数更是限制了上传文件的文件头必须为图像类型 23 24 // Can we move the file to the upload folder? 25 if( !move_uploaded_file( $uploaded_tmp, $target_path ) ) { 26 // No 27 echo '<pre>Your image was not uploaded.</pre>'; 28 } 29 else { 30 // Yes! 31 echo "<pre>{$target_path} succesfully uploaded!</pre>"; 32 } 33 } 34 else { 35 // Invalid file 36 echo '<pre>Your image was not uploaded. We can only accept JPEG or PNG images.</pre>'; 37 } 38} Impossible 1if( isset( $_POST[ 'Upload' ] ) ) { 2 // Check Anti-CSRF token 3 checkToken( $_REQUEST[ 'user_token' ], $_SESSION[ 'session_token' ], 'index.php' ); 4 5 // File information 6 $uploaded_name = $_FILES[ 'uploaded' ][ 'name' ]; 7 $uploaded_ext = substr( $uploaded_name, strrpos( $uploaded_name, '.' ) + 1); 8 $uploaded_size = $_FILES[ 'uploaded' ][ 'size' ]; 9 $uploaded_type = $_FILES[ 'uploaded' ][ 'type' ]; 10 $uploaded_tmp = $_FILES[ 'uploaded' ][ 'tmp_name' ]; 11 12 // Where are we going to be writing to? 13 $target_path = DVWA_WEB_PAGE_TO_ROOT . 'hackable/uploads/'; 14 //$target_file = basename( $uploaded_name, '.' . $uploaded_ext ) . '-'; 15 16 // MD5 加密 17 $target_file = md5( uniqid() . $uploaded_name ) . '.' . $uploaded_ext; 18 $temp_file = ( ( ini_get( 'upload_tmp_dir' ) == '' ) ? ( sys_get_temp_dir() ) : ( ini_get( 'upload_tmp_dir' ) ) ); 19 $temp_file .= DIRECTORY_SEPARATOR . md5( uniqid() . $uploaded_name ) . '.' . $uploaded_ext; 20 21 // Is it an image? 22 if( ( strtolower( $uploaded_ext ) == 'jpg' || strtolower( $uploaded_ext ) == 'jpeg' || strtolower( $uploaded_ext ) == 'png' ) && 23 ( $uploaded_size < 100000 ) && 24 ( $uploaded_type == 'image/jpeg' || $uploaded_type == 'image/png' ) && 25 getimagesize( $uploaded_tmp ) ) { 26 27 // Strip any metadata, by re-encoding image (Note, using php-Imagick is recommended over php-GD) 28 if( $uploaded_type == 'image/jpeg' ) { 29 $img = imagecreatefromjpeg( $uploaded_tmp ); 30 imagejpeg( $img, $temp_file, 100); 31 } 32 else { 33 $img = imagecreatefrompng( $uploaded_tmp ); 34 imagepng( $img, $temp_file, 9); 35 } 36 imagedestroy( $img ); 37 38 // Can we move the file to the web root from the temp folder? 39 if( rename( $temp_file, ( getcwd() . DIRECTORY_SEPARATOR . $target_path . $target_file ) ) ) { 40 // Yes! 41 echo "<pre><a href='${target_path}${target_file}'>${target_file}</a> succesfully uploaded!</pre>"; 42 } 43 else { 44 // No 45 echo '<pre>Your image was not uploaded.</pre>'; 46 } 47 48 // Delete any temp files 49 if( file_exists( $temp_file ) ) 50 unlink( $temp_file ); 51 } 52 else { 53 // Invalid file 54 echo '<pre>Your image was not uploaded. We can only accept JPEG or PNG images.</pre>'; 55 } 56} 57 58// Generate Anti-CSRF token 59generateSessionToken(); Extension 00%截断 ...
DVWA File upload 过关秘籍. LOW 1if( isset( $_POST[ 'Upload' ] ) ) { 2 // Where are we going to be writing to? 3 $target_path = DVWA_WEB_PAGE_TO_ROOT . "hackable/uploads/"; 4 $target_path .= basename( $_FILES[ 'uploaded' ][ 'name' ] ); 5 6 // Can we move the file to the upload folder? 7 // 完全没做过滤. 8 // 上传一个PHP文件也是可以的. 9 if( !move_uploaded_file( $_FILES[ 'uploaded' ][ 'tmp_name' ], $target_path ) ) { 10 // No 11 echo '<pre>Your image was not uploaded.</pre>'; 12 } 13 else { 14 // Yes! 15 echo "<pre>{$target_path} succesfully uploaded!</pre>"; 16 } 17} Medium 1if( isset( $_POST[ 'Upload' ] ) ) { 2 // Where are we going to be writing to? 3 $target_path = DVWA_WEB_PAGE_TO_ROOT . "hackable/uploads/"; 4 $target_path .= basename( $_FILES[ 'uploaded' ][ 'name' ] ); 5 6 // File information 7 $uploaded_name = $_FILES[ 'uploaded' ][ 'name' ]; 8 $uploaded_type = $_FILES[ 'uploaded' ][ 'type' ]; 9 $uploaded_size = $_FILES[ 'uploaded' ][ 'size' ]; 10 11 // Is it an image? 12 // // 开始做了一些过滤 13 14 // 下面是官方对$_FILES 函数的描述 15 // [name] => MyFile.txt (comes from the browser, so treat as tainted) 16 // [type] => text/plain (not sure where it gets this from - assume the browser, so treat as tainted) 17 // [tmp_name] => /tmp/php/php1h4j1o (could be anywhere on your system, depending on your config settings, but the user has no control, so this isn't tainted) 18 // [error] => UPLOAD_ERR_OK (= 0) 19 // [size] => 123 (the size in bytes) 20 21 // 其中对name和type的description的描述都是 `treat as tainted`(被污染的) 22 // 这意味着它有可能会被修改 unsafe 23 24 // 我们可以尝试上传一个PHP文件,使用一些拦截请求工具,修改即将发出的请求. 25 // 来达到修改`name`中的后缀名和`type`中的媒体类型. 26 if( ( $uploaded_type == "image/jpeg" || $uploaded_type == "image/png" ) && 27 ( $uploaded_size < 100000 ) ) { 28 29 // Can we move the file to the upload folder? 30 if( !move_uploaded_file( $_FILES[ 'uploaded' ][ 'tmp_name' ], $target_path ) ) { 31 // No 32 echo '<pre>Your image was not uploaded.</pre>'; 33 } 34 else { 35 // Yes! 36 echo "<pre>{$target_path} succesfully uploaded!</pre>"; 37 } 38 } 39 else { 40 // Invalid file 41 echo '<pre>Your image was not uploaded. We can only accept JPEG or PNG images.</pre>'; 42 } 43} High 1if( isset( $_POST[ 'Upload' ] ) ) { 2 // Where are we going to be writing to? 3 $target_path = DVWA_WEB_PAGE_TO_ROOT . "hackable/uploads/"; 4 $target_path .= basename( $_FILES[ 'uploaded' ][ 'name' ] ); 5 6 // File information 7 $uploaded_name = $_FILES[ 'uploaded' ][ 'name' ]; 8 // jpg 9 $uploaded_ext = substr( $uploaded_name, strrpos( $uploaded_name, '.' ) + 1); 10 11 // file size 12 $uploaded_size = $_FILES[ 'uploaded' ][ 'size' ]; 13 14 // tmp_name 是临时副本的名字 15 $uploaded_tmp = $_FILES[ 'uploaded' ][ 'tmp_name' ]; 16 17 // Is it an image? 18 // 和上面的比起来多个一个文件后缀名的判断. 19 // strtolower 转小写 20 // 扩展名只要满足jpeg,png或者jpg就行 21 if( ( strtolower( $uploaded_ext ) == "jpg" || strtolower( $uploaded_ext ) == "jpeg" || strtolower( $uploaded_ext ) == "png" ) && 22 ( $uploaded_size < 100000 ) && 23 // getimagesize 获取图像信息 24 // 这个函数保证你穿的一定得是个图像 25 // 可以用图片木马绕过 26 getimagesize( $uploaded_tmp ) ) { 27 28 // Can we move the file to the upload folder? 29 if( !move_uploaded_file( $uploaded_tmp, $target_path ) ) { 30 // No 31 echo '<pre>Your image was not uploaded.</pre>'; 32 } 33 else { 34 // Yes! 35 echo "<pre>{$target_path} succesfully uploaded!</pre>"; 36 } 37 } 38 else { 39 // Invalid file 40 echo '<pre>Your image was not uploaded. We can only accept JPEG or PNG images.</pre>'; 41 } 42} High 1if( isset( $_POST[ 'Upload' ] ) ) { 2 // Where are we going to be writing to? 3 $target_path = DVWA_WEB_PAGE_TO_ROOT . "hackable/uploads/"; 4 $target_path .= basename( $_FILES[ 'uploaded' ][ 'name' ] ); 5 6 // File information 7 $uploaded_name = $_FILES[ 'uploaded' ][ 'name' ]; 8 $uploaded_ext = substr( $uploaded_name, strrpos( $uploaded_name, '.' ) + 1); 9 $uploaded_size = $_FILES[ 'uploaded' ][ 'size' ]; 10 $uploaded_tmp = $_FILES[ 'uploaded' ][ 'tmp_name' ]; 11 12 // Is it an image? 13 // 对比上面多验证了文件的后缀名 14 if( ( strtolower( $uploaded_ext ) == "jpg" || strtolower( $uploaded_ext ) == "jpeg" || strtolower( $uploaded_ext ) == "png" ) && 15 ( $uploaded_size < 100000 ) && 16 17 18 19 // 函数会通过读取文件头,返回图片的长、宽等信息,如果没有相关的图片文件头,函数会报错 20 getimagesize( $uploaded_tmp ) ) { 21 22 // 可以看到,High级别的代码读取文件名中最后一个”.”后的字符串,期望通过文件名来限制文件类型 23 // 因此要求上传文件名形式必须是”*.jpg”、”*.jpeg” 、”*.png”之一 24 // 同时,getimagesize函数更是限制了上传文件的文件头必须为图像类型 25 26 // Can we move the file to the upload folder? 27 if( !move_uploaded_file( $uploaded_tmp, $target_path ) ) { 28 // No 29 echo '<pre>Your image was not uploaded.</pre>'; 30 } 31 else { 32 // Yes! 33 echo "<pre>{$target_path} succesfully uploaded!</pre>"; 34 } 35 } 36 else { 37 // Invalid file 38 echo '<pre>Your image was not uploaded. We can only accept JPEG or PNG images.</pre>'; 39 } 40} Impossible 1if( isset( $_POST[ 'Upload' ] ) ) { 2 // Check Anti-CSRF token 3 checkToken( $_REQUEST[ 'user_token' ], $_SESSION[ 'session_token' ], 'index.php' ); 4 5 // File information 6 $uploaded_name = $_FILES[ 'uploaded' ][ 'name' ]; 7 $uploaded_ext = substr( $uploaded_name, strrpos( $uploaded_name, '.' ) + 1); 8 $uploaded_size = $_FILES[ 'uploaded' ][ 'size' ]; 9 $uploaded_type = $_FILES[ 'uploaded' ][ 'type' ]; 10 $uploaded_tmp = $_FILES[ 'uploaded' ][ 'tmp_name' ]; 11 12 // Where are we going to be writing to? 13 $target_path = DVWA_WEB_PAGE_TO_ROOT . 'hackable/uploads/'; 14 //$target_file = basename( $uploaded_name, '.' . $uploaded_ext ) . '-'; 15 16 // MD5 加密 17 $target_file = md5( uniqid() . $uploaded_name ) . '.' . $uploaded_ext; 18 $temp_file = ( ( ini_get( 'upload_tmp_dir' ) == '' ) ? ( sys_get_temp_dir() ) : ( ini_get( 'upload_tmp_dir' ) ) ); 19 $temp_file .= DIRECTORY_SEPARATOR . md5( uniqid() . $uploaded_name ) . '.' . $uploaded_ext; 20 21 // Is it an image? 22 if( ( strtolower( $uploaded_ext ) == 'jpg' || strtolower( $uploaded_ext ) == 'jpeg' || strtolower( $uploaded_ext ) == 'png' ) && 23 ( $uploaded_size < 100000 ) && 24 ( $uploaded_type == 'image/jpeg' || $uploaded_type == 'image/png' ) && 25 getimagesize( $uploaded_tmp ) ) { 26 27 // Strip any metadata, by re-encoding image (Note, using php-Imagick is recommended over php-GD) 28 if( $uploaded_type == 'image/jpeg' ) { 29 $img = imagecreatefromjpeg( $uploaded_tmp ); 30 imagejpeg( $img, $temp_file, 100); 31 } 32 else { 33 $img = imagecreatefrompng( $uploaded_tmp ); 34 imagepng( $img, $temp_file, 9); 35 } 36 imagedestroy( $img ); 37 38 // Can we move the file to the web root from the temp folder? 39 if( rename( $temp_file, ( getcwd() . DIRECTORY_SEPARATOR . $target_path . $target_file ) ) ) { 40 // Yes! 41 echo "<pre><a href='${target_path}${target_file}'>${target_file}</a> succesfully uploaded!</pre>"; 42 } 43 else { 44 // No 45 echo '<pre>Your image was not uploaded.</pre>'; 46 } 47 48 // Delete any temp files 49 if( file_exists( $temp_file ) ) 50 unlink( $temp_file ); 51 } 52 else { 53 // Invalid file 54 echo '<pre>Your image was not uploaded. We can only accept JPEG or PNG images.</pre>'; 55 } 56} 57 58// Generate Anti-CSRF token 59generateSessionToken(); Extension 00%截断 ...