Forum Moderators: coopster

Message Too Old, No Replies

I need to save image from a site to my server

I need to save image from a site to my server

         

The_Beast

10:52 pm on Dec 29, 2008 (gmt 0)

10+ Year Member



I need to save image from a site to my server, I have this so far.. but im getting this error
Parse error: syntax error, unexpected $end in /home/sglove/domains/example.com/public_html/Models_old/check.php on line 26

<?php
// REPLACE FIELDS
mysql_connect("localhost", "#*$!x", "#*$!x") or die(mysql_error());

mysql_select_db("#*$!x") or die(mysql_error());
$query="SELECT * FROM #*$!x";
$result=mysql_query($query);
$num=mysql_numrows($result);
$i=0;
while ($i < $num) {
$dirname=mysql_result($result,$i,"dirname");

$ch = curl_init ("http://example.com/Models/$dirname/1.jpg");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_BINARYTRANSFER,1);
$rawdata=curl_exec ($ch);
curl_close ($ch);
mkdir($dirname, 0777);
$fp = fopen("$dirname/1.jpg",'w');
fwrite($fp, $rawdata);
fclose($fp);

?>

please advise!

[edited by: eelixduppy at 11:33 pm (utc) on Dec. 29, 2008]
[edit reason] please use example.com, thanks [/edit]

sonjay

3:00 am on Dec 30, 2008 (gmt 0)

10+ Year Member



You have two problems that leap out at me. The syntax error is caused by a missing close curly brace. This line is missing its closing brace:
while ($i < $num) {

The second problem is, you don't increment the $i anywhere, so if $num is > 0 $i will always be less than $num, and your while loop will continue forever.

The_Beast

3:31 am on Dec 30, 2008 (gmt 0)

10+ Year Member



i dont know php, i just guess when i put it together, what would it look like? i dont know where to put these things...