08-05-2009, 09:18 AM
|
#7 (permalink)
|
|
The Contributor
Join Date: Jul 2009
Posts: 80
Thanks: 13
|
This is my code
PHP Code:
$filename = $_POST['imageq'];
if (!$bonushsystemconnect)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("bonush_sy6", $bonushsystemconnect);
$imageresult = mysql_query('SELECT id FROM isearch WHERE imageurl="$filename"');
if(mysql_num_rows($imageresult) > 0) {
print "Already In DB";
end;
}else{
//congrats! you added an apple to the basket.
$ran = md5(uniqid(mt_rand(), true));
$size = getimagesize($filename);
switch ($size['mime']) {
case "image/gif":
$type= ".gif";
break;
case "image/jpeg":
$type= ".jpg";
break;
case "image/png":
$type= ".png";
break;
case "image/bmp":
$type= ".bmp";
break;
}
$test = $ran;
$test = $test.''.$type;
$fh = fopen("$test", 'w') or die("can't open file");
if($fh==false)
die("unable to create file");
if(!@copy ($filename,$test))
{
$errors= error_get_last();
echo "COPY ERROR: ".$errors['type'];
echo "<br />\n".$errors['message'];
} else {
echo "File copied from remote!";
$sql="INSERT INTO isearch (site, imageurl, oururl, keywords) VALUES ('Peter', '$filename', '$test', 'lol')";
if (!mysql_query($sql, $bonushsystemconnect))
{
die('Error: ' . mysql_error());
}
echo "1 record added";
}
}
For some reason the if statement to stop it going on an adding the new row or copying the image, it seems to ether not be checking the DB or there is something wrong with placing if statements in side else statements?
Last edited by codefreek : 08-05-2009 at 01:25 PM.
Reason: PHP tags added - please read http://www.talkphp.com/lounge/4563-prettifying-pasted-code-talkphp.html
|
|
|
|