Created
February 24, 2014 09:53
-
-
Save zsmynl/9184820 to your computer and use it in GitHub Desktop.
php图片采集后按原路径保存图片
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$domain ='http://www.xxxx.com'; | |
$url = '/newskin/images/v4/logo.jpg'; | |
$pats = pathinfo($url); | |
$dir = '.'.$pats['dirname'].'/'; | |
if(!is_dir($dir)) | |
{ | |
@mkdirs($dir, 0777); | |
@fclose(fopen($dir.'/index.htm', 'w')); | |
} | |
$img = file_get_contents($domain.$url); | |
file_put_contents('.'.$url,$img); | |
echo '<img src="'.$url.'">'; | |
function mkdirs($pathname, $mode = 0755){ | |
is_dir(dirname($pathname)) || mkdirs(dirname($pathname), $mode); | |
return is_dir($pathname) || @mkdir($pathname, $mode); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment