使用PHP创建迷你个人资料,上传照片时遇到问题并将其分配给每个成员


creating a mini profile with php, having issues with upload photo and assigning the to each member

我正在尝试创建一个迷你个人资料,其中显示人员姓名,在公司中的位置,电话号码,电子邮件,简历和个人资料照片的插槽。我的问题是我已经知道如何上传图像并裁剪它们,但是我已经狂热地搜索无济于事,试图找出一种可以上传配置文件以链接每个用户ID的方法,例如。就像您的Facebook个人资料图片如何自动链接到您的用户ID一样,有什么建议吗?我是否必须使用相同的数据库(Mysql)表才能这样做?或者我可以调用特定的 ID?如果我想稍后更改同一配置文件的图片,我是否必须重新创建配置文件?或者有没有办法标记每个个人资料并在点击时访问每个个人资料?

<?php
error_reporting(0);
include('connect.php');
if(is_dir('hftpnyc/dir_thumbs') == false ){
mkdir('hftpnyc/dir_thumbs', 0744);} 
$dir_pos = mysql_real_escape_string($_POST['Dir_pos']);
$dir_name=mysql_real_escape_string($_POST['Dir_name']);
$occu=mysql_real_escape_string($_POST['Occu']);
$bio = mysql_real_escape_string($_POST['Bio']);
$pic = mysql_real_escape_string($_POST['dir_pic']);
$email = mysql_real_escape_string($_POST['email']);
$Numb = mysql_real_escape_string($_POST['num']);
$cr8 = isset($_POST['cr8']);
$errmsg = array();
$sql= mysql_query("SELECT * FROM `directors`");
$get = mysql_fetch_assoc($sql);
if($cr8){
if( $dir_pos && $dir_name && $occu){
    mysql_query("INSERT INTO `hftpnyc`.`directors` (`Positition`,`name`,`Email`,`Num`,`occupation`,`Bio`,`dir_pic`) VALUES     ('{$dir_pos}','{$dir_name}','{$email}','{$Numb}','{$occu}','{$bio}','{$encoded}')");
header('location:Directors.php');
}
}
?>
<form name="Director_create" method="post" id="form" actio="<?php echo $_SERVER['PHP_SELF']; ?>"/>
Director position: <br/> 
<input class="text_user"  id="nick" type="text" name="Dir_pos" MAXLENGTH="55"   />  
Director name:
<input  name="Dir_name" type="text" id="messagebox" />

Contact Number:
<p style="color:#F00; font-size:9px; margin-top:0px; margin-bottom:0px;">*optional*</p>
   <input  name="num" type="text" id="messagebox" />
Email Address:
<input  name="email" type="text" id="messagebox" />
Occupation:
<input  name="Occu" cols="20" class="text" id="messagebox" />

Biography:
<textarea ty  name="Bio" class="text" id="messagebox"  ></textarea>
<br/> 
<input id="send" name="cr8" type="submit" value="CREATE" /> 
</form>

我有代码来显示下面每个配置文件的回声。

<?php
$query=mysql_query("SELECT * FROM `directors` ORDER BY  `Director_id` DESC;") ;
while ($row=mysql_fetch_assoc($query))
{
$email1 = $row['Email'];
$enc = $row['dir_pic'];
$name= $row['name'];
$posit = $row['Positition'];
$num1 = $row['Num'];
$occupation = $row['occupation'];
$Biography = $row['Bio']; 
?>
<div id="direc" style="height:10px; width:100%;margin-bottom:8px;">
<h3 class="heading" style="margin:0px auto;color:#666; border-bottom: #A3308E solid 1px;font-family: Tahoma, Geneva, sans-serif; font-size:15px"> <?php echo $posit; ?>: <?php    echo $name; ?></h3> </div>
<div class="photocase" style="width:100px; height:100px; float:left;border-width: 1px;border:solid black 1px;margin: 5px; ">
<img src="<?php echo /*This is where i want each photo*/; ?>" width="100px" />
</div>
<div  style="width:360px;height:30px; display:block;float:left;margin-top:5px; line-height:3px;">
<p>OCCUPATION: <?php echo $occupation; ?></p>
</div>    
<div  style="width:360px;height:30px; display:block;float:left;margin-top:5px; line-height:3px;">
<p align="justify">Email: <?php echo $email1; ?></p>
</div>  
<div  style="width:360px;height:30px; display:block;float:left;margin-top:5px; line-height:3px;">
<p align="justify">Contact #: <?php echo $num1; ?></p>
</div>

<div style="float:left;display:block;width:98%;height:16px;margin-bottom:0px;margin-left:1.5%; ">
<p>Bio:<?php echo $Biography;?></p>
</div>
</div>
<?php

}
?>

创建一个类似用户的表,该表将包含用户的所有典型信息。在同一表中有一个名为 like profile_pic 的列,其中可能只包含图像名称或图像的整个路径。在这种情况下,您只存储图像名称,请确保将所有图像上传到特定文件夹。这里的问题是,随着更多的用户被添加到数据库中,该文件夹变得非常大。解决它的一种方法是为新月份自动创建一个新文件夹。稍后,当您要访问配置文件的图像时,您可以从用户创建时间的时间戳中知道该文件夹。

来到您的第二个问题,即如何访问配置文件,它非常简单。每个表创建的最基本方法是具有一个名为 id 的键/列,它将是表的主键。这当然是独一无二的。因此,每个用户都使用称为 id 的键进行引用。您可以为此列放置一个增量属性。因此,每次您添加新用户时,mysql 都会自动创建他的 ID 号。

现在假设用户的 id 是 43。要查看特定的配置文件,您将有一个名为配置文件的页面.php

如果请求类似于

profile.phP?id=43  

然后从 $_GET['id'],您可以在数据库中查询,例如

'select * from users where id = "'.$_GET['id'].'" ';