我是新來的php,並試圖上傳文件並將上載的文件存儲在數據庫中的當前登錄用戶ID,這是我的上傳文件格式:如何獲取用戶ID並將其存儲到數據庫
<?php
error_reporting(E_ALL^E_NOTICE);
session_start();
?>
<form method="post" enctype="multipart/form-data">
<table width="350" border="0" cellpadding="1"
cellspacing="1" class="box">
<tr>
<td>please select a file</td></tr>
<tr>
<td>
<input type="hidden" name="MAX_FILE_SIZE"
value="16000000">
<input name="pdf" type="file" id="pdf" accept="application/pdf">
</td>
<td width="80"><input name="upload"
type="submit" class="box" id="upload" value=" Upload "></td>
</tr>
</table>
</form>
</body>
</html>
<?php
if(isset($_POST['upload'])&&$_FILES['pdf']['size']>0)
{
$fileName = $_FILES['userfile']['name'];
$tmpName = $_FILES['userfile']['tmp_name'];
$fileSize = $_FILES['userfile']['size'];
$filePath = $_FILES['userfile']['path'];
$fileType = $_FILES['userfile']['type'];
$fileType=(get_magic_quotes_gpc()==0 ? mysql_real_escape_string(
$_FILES['userfile']['type']) : mysql_real_escape_string(
stripslashes ($_FILES['userfile'])));
$fp = fopen($tmpName, 'r');
$content = fread($fp, filesize($tmpName));
$content = addslashes($content);
fclose($fp);
if(!get_magic_quotes_gpc())
{
$fileName = addslashes($fileName);
}
$con = mysql_connect('localhost', 'root', '') or die(mysql_error());
$db = mysql_select_db('workflow', $con);
if($db){
$query = "INSERT INTO upload (name, size, type, path ) ".
"VALUES ('$fileName', '$fileSize', '$fileType', '$filePath')";
mysql_query($query) or die('Error, query failed');
mysql_close();
echo "<br>File $fileName uploaded<br>";
}else { echo "file upload failed"; }
}
?>
,這是我的登錄表單:
<?php
error_reporting(E_ALL^E_NOTICE);
session_start();
?>
<!DOCTYPE html>
<html>
<head>
<title>LOGIN FORM</title>
</head>
<body>
<?php
$form= "<form action='login.php' method='post'>
<table>
<tr>
<td>username :</td>
<td><input type='text' name='user'/></td>
</tr>
<tr>
<td>Password :</td>
<td><input type='password' name='password'/></td>
</tr>
<tr>
<td></td>
<td><input type='submit' name='loginbtn' value='login' /></td>
</tr>
</table>
</form>";
if ($_POST['loginbtn']) {
$user = $_POST['user'];
$password = $_POST['password'];
if ($user) {
if ($password) {
require ("connect1.php");
$password= md5(md5("jdhbjdbj".$password."jdh645fdj"));
$query = mysql_query("SELECT * FROM users WHERE username='$user'");
$numrows = mysql_num_rows($query);
if ($numrows == 1) {
$row = mysql_fetch_assoc($query);
$dbid=$row['id'];
$dbuser=$row['username'];
$dbpass=$row['password'];
$dbactive=$row['active'];
if ($password == $dbpass) {
if ($dbactive == 1) {
$_SESSION['userid'] = $dbid;
$_SESSION['username'] = $dbuser;
echo "you have been logged in as <b>$dbuser</b>. <a href='insert1.php' >Click here</a> to go to the insertion page ";
}
else echo "you must activate your account to login .$form";
}
else echo "You didn't enter a password . $form";
}
else echo "the user name u entered wasn't found . $form";;
mysql_close();
}
else echo "You must enter your password .$form";
}
else echo "You must enter your username .$form";
}
else echo $form;
?>
</body>
</html>
我想獲得當前用戶ID,並將它與文件存儲我上載她的任何一個可以幫助???
當用戶在你的系統中存儲了他的詳細信息?在會議或其他事情? –
@ A-2-A是的,我打開一個會話,當他登錄 –
上傳是否工作?Shoudnt this'$ _FILES ['userfile'] ['name']'是'$ _FILES ['pdf'] [''名字']'等等? – Mihai