Am getting syntax errors on 2 lines which doesnt seem to have any problem at all:
<?php
ob_start();
echo"Upload files section";
?>
<br><br>
<?
session_start();
echo "Hi ".$_SESSION['username'];
function display_upload_form()
{
echo <<<DISPLAY_UPLOAD_FORM
?>
<table width="500" border="3" align="center" cellpadding="0" cellspacing="1">
<form name="Upload files" action="{$_SERVER['PHP_SELF']}" method="post" enctype="multipart/form-data">
<link rel="stylesheet" type="text/css" href="main.css"/>
<tr>
<table width="100%" border="3" cellpadding="3" cellspacing="1">
<tr>
<td colspan="3"><strong>File Upload</strong></td>
<tr>
<td width="150">Select file</td>
<td><input type="file" name="uploadNeed" id="ufile" size="50"></td>
<td><input type="hidden" name="execute" value="1"></td>
</tr>
<tr>
<td align="center"><input type="Submit" name="Submit" value="Upload"/></td>
</tr>
<tr>
<td align="center"><a href="one.php">Back</a>
</tr>
</table>
</form>
</td>
</table>
<?
DISPLAY_UPLOAD_FORM;}
function execute_upload()
{
phpinfo();
// root path
$path = "uploads/";
$path = $path.basename( $_FILES[uploadNeed][name]);
// upload directory. path will originate from root.
$dirname = '/uploads';
// permission settings for newly created folders
$chmod = 0755;
//open connection to mysql server
$con = mysql_connect("localhost","root","root");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("my_db", $con);
//creating file variables
$fp = fopen($tmp_name, 'r');
$content = fread($fp, filesize($tmp_name));
fclose($fp);
$filename = $_FILES['uploadNeed']['name']; ---> [COLOR="red"]it shows syntax errors in all these statements. I dont understand y this is happening[/COLOR] $filesize = $_FILES['uploadNeed']['size'];
$filetype = $_FILES['uploadNeed']['type'];
$file_tmp = $_FILES['uploadNeed']['tmp_name'];
$file_err = $_FILES['uploadNeed']['error'];
$file_ext = strrchr($filename, '.');
// check to prevent file attacks.
if (is_uploaded_file($file_tmp))
{
/
check if the directory exists
if it doesnt exist, make the directory
/
$dir = $path . $dirname;
if (!is_dir($dir))
{
$dir = explode('/', $dirname);
foreach ($dir as $sub_dir)
{
$path .= '/' . $sub_dir;
if (!is_dir($path))
{
if (!mkdir($path, $chmod))
{
unlink($file_tmp);
die('<strong>Error:</strong> Directory does not exist and was unable to be created.');
}
}
}
}
/*
* copy the file from the temporary upload directory
* to its final detination.
*/
if (move_uploaded_file($file_tmp, $dir . '/' . $filename))
{
// success!
echo "
<p>Success!</p>
<p><strong>View File:</strong> <a href=\"$dirname/$filename\">$filename</a></p>
";
}
else
{
// error moving file. check file permissions.
unlink($file_tmp);
echo '<strong>Error:</strong> Unable to move file to designated directory.';
}
}
else
{
// file seems suspicious... delete file and error out.
unlink($file_tmp);
echo '<strong>Error:</strong> File does not appear to be a valid upload. Could be a file attack.';
}
}
// Kill temp file, if any, and display error.
if ($file_tmp != '')
{
unlink($file_tmp);
}
switch ($file_err)
{
case '0':
echo 'That is not a valid file. 0 byte length.';
break;
case '1':
echo 'This file, at ' . $filesize . ' bytes, exceeds the maximum allowed file size as set in <em>php.ini</em>. '.
'Please contact your system admin.';
break;
case '2':
echo 'This file exceeds the maximum file size specified in your HTML form.';
break;
case '3':
echo 'File was only partially uploaded. This could be the result of your connection '.
'being dropped in the middle of the upload.';
case '4':
echo 'You did not upload anything... Please go back and select a file to upload.';
break;
}
// Logic Code
if (isset($_POST['execute'])) ---> it shows syntax error here
{
execute_upload();
}
else
{
display_upload_form();
}
ob_end_flush();
?>
}