Home >php教程 >PHP源码 >PHP按原路径保存图片

PHP按原路径保存图片

PHP中文网
PHP中文网Original
2016-05-25 17:00:021079browse

php代码

<?php
$domain =&#39;http://www.china-textileduct.com&#39;;
$url = &#39;/newskin/images/v4/logo.jpg&#39;;
$pats = pathinfo($url);
$dir = &#39;.&#39;.$pats[&#39;dirname&#39;].&#39;/&#39;;
		if(!is_dir($dir))
			{
				@mkdirs($dir, 0777);
				@fclose(fopen($dir.&#39;/index.htm&#39;, &#39;w&#39;));
			}
$img = file_get_contents($domain.$url);
file_put_contents(&#39;.&#39;.$url,$img); 
echo &#39;<img src="&#39;.$url.&#39;">&#39;;

function mkdirs($pathname, $mode = 0755){
	is_dir(dirname($pathname)) || mkdirs(dirname($pathname), $mode);
	return is_dir($pathname) || @mkdir($pathname, $mode);
}
?>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn