我试图允许用户将 2 个图像上传到他们注册时创建的文件夹,并在上传时将两个文件的后续路径插入到我的表中,该表具有“main”作为第一个图像路径,“one”作为下一个图像路径。
上传者正确地将这两个文件上传到文件夹中,但是我是否执行插入以将图像一个路径插入“主”,并将图像两个路径插入“一个”?
上传代码如下......
非常感谢任何帮助!
<?php
$userid = $_SESSION['userid'];
$username = $_SESSION['user_name'];
$uploadDir = "images/test/$username/";
$uploadsNeeded = '2';
for($i = 0; $i < $uploadsNeeded; $i++){
$file_name = $_FILES['uploadFile'. $i]['name'];
// strip file_name of slashes
$file_name = stripslashes($file_name);
$file_name = str_replace("'","",$file_name);
$copy = copy($_FILES['uploadFile'. $i]['tmp_name'],$uploadDir . $file_name);
// prompt if successfully copied
if($copy){
echo "$file_name | uploaded sucessfully!<br>";
}else{
echo "$file_name | could not be uploaded!<br>";
}
$filePath = $uploadDir . $file_name;
$sql = "UPDATE images SET main = '$filePath' WHERE userid = '$_SESSION[userid]'";
$result = @mysql_query($sql, $connection) or die(mysql_error());
$sql = "UPDATE images SET one = '$filePath' WHERE userid = '$_SESSION[userid]'";
$result = @mysql_query($sql, $connection) or die(mysql_error());
}
?>