首页 > php开发

PHP通过url下载远程图片到本地

实例

<?php
/**
 * 通过图片的远程url,下载到本地
 * @param: $url为图片远程链接
 * @param: $filename为下载图片后保存的文件名
 */
function GrabImage($url,$filename) {
 if($url==""):return false;endif;
 
 ob_start();
 readfile($url);
 $img = ob_get_contents();
 ob_end_clean();
 $size = strlen($img);
 
 //"../../images/books/"为存储目录,$filename为文件名
 $fp2=@fopen("../../images/books/".$filename, "a");
 fwrite($fp2,$img);
 fclose($fp2);
 
 return $filename;
 }
?>

阅读全文

Magento 获取购物车产品数量和价格程序代码

得到购物车所有的产品信息

// $items = Mage::getModel('checkout/cart')->getQuote()->getAllItems();
$items = Mage::getSingleton('checkout/session')->getQuote()->getAllItems();foreach($items as $item) {
    echo 'ID: '.$item->getProductId().'<br>';
    echo 'Name: '.$item->getName().'<br>';
    echo 'Sku: '.$item->getSku().'<br>';
    echo 'Quantity: '.$item->getQty().'<br>';
    echo 'Price: '.$item->getPrice().'<br>';
    echo "<br>";
}

阅读全文

PHP移除指定HTML标签方法总结

有时候我们需要把html标签页存到数据库里,但是有些场合却需要拿无html标签的纯数据,这个时候就要对带html标签的数据进行处理,把html标签都去掉。平时用 htmlspecialchars() 来过滤html,但是把html的字符转义了,最后显示出来的就是html源代码,利用strip_tags()就可以把html标签去除掉。

阅读全文

php curl 伪造IP来源程序实现代码

定义伪造用户浏览器信息HTTP_USER_AGENT

$binfo =array('Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 2.0.50727; InfoPath.2; AskTbPTV/5.17.0.25589; Alexa Toolbar)','Mozilla/5.0 (Windows NT 5.1; rv:22.0) Gecko/20100101 Firefox/22.0','Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET4.0C; Alexa Toolbar)','Mozilla/4.0(compatible; MSIE 6.0; Windows NT 5.1; SV1)',$_SERVER['HTTP_USER_AGENT']);
//123.125.68.*
//125.90.88.*

阅读全文

php 删除非空目录自定义函数

//循环删除目录和文件函数

function delDirAndFile( $dirName )
{
if ( $handle = opendir( “$dirName” ) ) {
while ( false !== ( $item = readdir( $handle ) ) ) {
if ( $item != “.” && $item != “..” ) {
if ( is_dir( “$dirName/$item” ) ) {
delDirAndFile( “$dirName/$item” );
} else {
if( unlink( “$dirName/$item” ) )echo “成功删除文件: $dirName/$item
n”;
}
}
}
closedir( $handle );
if( rmdir( $dirName ) )echo “成功删除目录: $dirName
n”;
}
}
?>

阅读全文