christsealed
New member
For some reason, when I check this code, I get the following error.
Parse error: parse error, unexpected T_CONSTANT_ENCAPSED_STRING in fpi_upload.php on line 68
I've checked and apparently it's due to some basic syntax error, but I can't find it when I check. Help?
<?php
$host = '';
$dbuser = '';
$dbpass = '';
$dbname = '';
$table = '';
$db = mysql_connect($host,$dbuser,$dbpass) or die("error=could not connect to $host");
$db = mysql_select_db($dbname);
if(!$db)
{
print "error=could not connect to $dbname table";
exit;
}
//define a maxim size for the uploaded images in Kb
define ("MAX_SIZE","1000");
//This function reads the extension of the file. It is used to determine if the file is an image by checking the extension.
function getExtension($str) {
$i = strrpos($str,".");
if (!$i) { return ""; }
$l = strlen($str) - $i;
$ext = substr($str,$i+1,$l);
return $ext;
}
//This variable is used as a flag. The value is initialized with 0 (meaning no error found)
//and it will be changed to 1 if an errro occures.
//If the error occures the file will not be uploaded.
$errors=0;
$errmess='';
$errmess1='';
//checks if the form has been submitted
if(isset($_POST['Submit']))
{
//reads the name of the file the user submitted for uploading
$image=$_FILES['image']['name'];
//if it is not empty
if ($image)
{
//get the original name of the file from the clients machine
$filename = stripslashes($_FILES['image']['name']);
//get the extension of the file in a lower case format
$extension = getExtension($filename);
$extension = strtolower($extension);
//if it is not a known extension, we will suppose it is an error and will not upload the file,
//otherwise we will do more tests
if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png") && ($extension != "gif"))
{
//print error message
$errmess='Please submit only .jpg, .jpeg, .png & .gif files!';
$errors=1;
}
else
{
//get the size of the image in bytes
//$_FILES['image']['tmp_name'] is the temporary filename of the file
//in which the uploaded file was stored on the server
$size=filesize($_FILES['image']['tmp_name']);
//compare the size with the maxim size we defined and print error if bigger
if ($size > MAX_SIZE*1024)
{
$errmess='You have exceeded the size limit!';
$errors=1;
}
$sql="SELECT imageName FROM $table WHERE MD5 = "'.md5_file($_FILES['image']['tmp_name']).'"";
$result = mysql_query($sql) or die("Couldn't execute query.");
$num_rows = mysql_num_rows($result);
$uploads_dir='images/FPImages';
if($num_rows==1) {
$errmess="File already exists!";
} else {
$moved = move_uploaded_file($_FILES['image']['tmp_name'], "$uploads_dir/$filename");
$insert="INSERT INTO uploaded_images (imageDirectory, imageName) VALUES ('images/FPImages/', '$filename')";
if (!$moved)
{
$errmess='File Upload Unsuccessful!';
$errors=1;
}}}}}
//If no errors registred, print the success message
if(isset($_POST['Submit']) && !$errors)
{
$errmess1='File Uploaded Successfully!';
}
?>
<link href="upload.css" rel="stylesheet" type="text/css" />
<form name="storeImage" method="post" enctype="multipart/form-data" action="">
<div id="container">
<div id="mainer1">
<div id="form"><input type="file" name="image">
<br />
<br />
<input name="Submit" type="submit" value="Upload image">
<br />
<br />
<font color="#CC0000"><b><?php echo $errmess; ?></b></font>
<font color="#3366FF"><b><?php echo $errmess1; ?></b></font>
</div>
</div>
</div>
</form>
BTW: Line 68 is this one:
$sql="SELECT imageName FROM $table WHERE MD5 = "'.md5_file($_FILES['image']['tmp_name']).'"";
Parse error: parse error, unexpected T_CONSTANT_ENCAPSED_STRING in fpi_upload.php on line 68
I've checked and apparently it's due to some basic syntax error, but I can't find it when I check. Help?
<?php
$host = '';
$dbuser = '';
$dbpass = '';
$dbname = '';
$table = '';
$db = mysql_connect($host,$dbuser,$dbpass) or die("error=could not connect to $host");
$db = mysql_select_db($dbname);
if(!$db)
{
print "error=could not connect to $dbname table";
exit;
}
//define a maxim size for the uploaded images in Kb
define ("MAX_SIZE","1000");
//This function reads the extension of the file. It is used to determine if the file is an image by checking the extension.
function getExtension($str) {
$i = strrpos($str,".");
if (!$i) { return ""; }
$l = strlen($str) - $i;
$ext = substr($str,$i+1,$l);
return $ext;
}
//This variable is used as a flag. The value is initialized with 0 (meaning no error found)
//and it will be changed to 1 if an errro occures.
//If the error occures the file will not be uploaded.
$errors=0;
$errmess='';
$errmess1='';
//checks if the form has been submitted
if(isset($_POST['Submit']))
{
//reads the name of the file the user submitted for uploading
$image=$_FILES['image']['name'];
//if it is not empty
if ($image)
{
//get the original name of the file from the clients machine
$filename = stripslashes($_FILES['image']['name']);
//get the extension of the file in a lower case format
$extension = getExtension($filename);
$extension = strtolower($extension);
//if it is not a known extension, we will suppose it is an error and will not upload the file,
//otherwise we will do more tests
if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png") && ($extension != "gif"))
{
//print error message
$errmess='Please submit only .jpg, .jpeg, .png & .gif files!';
$errors=1;
}
else
{
//get the size of the image in bytes
//$_FILES['image']['tmp_name'] is the temporary filename of the file
//in which the uploaded file was stored on the server
$size=filesize($_FILES['image']['tmp_name']);
//compare the size with the maxim size we defined and print error if bigger
if ($size > MAX_SIZE*1024)
{
$errmess='You have exceeded the size limit!';
$errors=1;
}
$sql="SELECT imageName FROM $table WHERE MD5 = "'.md5_file($_FILES['image']['tmp_name']).'"";
$result = mysql_query($sql) or die("Couldn't execute query.");
$num_rows = mysql_num_rows($result);
$uploads_dir='images/FPImages';
if($num_rows==1) {
$errmess="File already exists!";
} else {
$moved = move_uploaded_file($_FILES['image']['tmp_name'], "$uploads_dir/$filename");
$insert="INSERT INTO uploaded_images (imageDirectory, imageName) VALUES ('images/FPImages/', '$filename')";
if (!$moved)
{
$errmess='File Upload Unsuccessful!';
$errors=1;
}}}}}
//If no errors registred, print the success message
if(isset($_POST['Submit']) && !$errors)
{
$errmess1='File Uploaded Successfully!';
}
?>
<link href="upload.css" rel="stylesheet" type="text/css" />
<form name="storeImage" method="post" enctype="multipart/form-data" action="">
<div id="container">
<div id="mainer1">
<div id="form"><input type="file" name="image">
<br />
<br />
<input name="Submit" type="submit" value="Upload image">
<br />
<br />
<font color="#CC0000"><b><?php echo $errmess; ?></b></font>
<font color="#3366FF"><b><?php echo $errmess1; ?></b></font>
</div>
</div>
</div>
</form>
BTW: Line 68 is this one:
$sql="SELECT imageName FROM $table WHERE MD5 = "'.md5_file($_FILES['image']['tmp_name']).'"";