卷曲和PHP问题 - 空白页

时间:2009-01-21 13:08:17

标签: php curl

我正在尝试将保存在网址中的图片下载到本地文件夹,并尝试使用curl进行以下操作。我想知道是否有必要包括curl或下载seperateley,或者我的功能是否正常工作。我想知道下面的实现是否有任何明显的问题。我知道sql漏洞,我正在转向准备好的语句。为简洁起见,我修剪了代码中不相关的部分。

编辑:该函数不在while循环中。如果我将该功能注释掉,则显示该页面,否则我只会得到一个空白页面。这是为什么

<?php
header("Content-Type: text/html; charset=utf-8");
if (isset($_GET["cmd"]))

  $cmd = $_GET["cmd"];

else

  die("You should have a 'cmd' parameter in your URL");

 $pk = $_GET["pk"];

$con = mysql_connect("localhost","someuser","notreal");

if(!$con)

{

die('Connection failed because of' .mysql_error());

}
mysql_query('SET NAMES utf8'); 

mysql_select_db("somedb",$con);

if($cmd=="GetAuctionData")

{

$sql="SELECT * FROM AUCTIONS WHERE ARTICLE_NO ='$pk'";

$sql2="SELECT ARTICLE_DESC FROM AUCTIONS WHERE ARTICLE_NO ='$pk'";

$htmlset = mysql_query($sql2);

$row2 = mysql_fetch_array($htmlset);



$result = mysql_query($sql);

function savePicture($imageUrl) {
    $ch = curl_init();
    curl_setopt ($ch, CURLOPT_URL, $lastImg);
    curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, 0);
    $fileContents = curl_exec($ch);
    curl_close($ch);
    $newImg = imagecreatefromstring($fileContents);
    return imagejpeg($newImg, "./{$pk}.jpg",100);
}

while ($row = mysql_fetch_array($result))
{



$lastImg = $row['PIC_URL']; 


savePicture($lastImg);


<div id='rightlayer'>

<img src='./".$pk.".jpg' width='".$outputWidth."' height='".$outputHeight."'>


</div>

</div>

</div>";



}



}

mysql_free_result($result);

2 个答案:

答案 0 :(得分:1)

如果在循环运行多次时在循环内声明一个函数,则会出现错误。因此,您应在savePicture之外声明while函数。

答案 1 :(得分:0)

我从while块中取出函数定义。

在我看来,为了在这里使用curl你使用curl,一个更简单的方法是使用file get contents

相关问题