所以基本上我有一个网站,允许某些成员将图像(漫画页面)上传到他们自己的图像库(特定漫画)。我有一个成功的图像上传脚本,用于为每个成员上传个人资料/头像图像,但现在我想将文件上传到更具体的地方,我遇到了一些麻烦。
这是我到目前为止所拥有的:
(这是出现在页面顶部的内容)
<?php
session_start();
$toplinks = "";
if (isset($_SESSION['id'])) {
// Put stored session variables into local php variable
$userid = $_SESSION['id'];
$username = $_SESSION['username'];
$toplinks = '<a href="member_profile.php?id=' . $userid . '">' . $username . '</a> •
<a href="member_account.php">Account</a> •
<a href="logout.php">Log Out</a>';
} else {
$toplinks = '<a href="join_form.php">Register</a> • <a href="login.php">Login</a>';
}
?>
(这是上传脚本)
<?php
// Here we run a login check
if (!isset($_SESSION['id'])) {
echo 'Please <a href="login.php">log in</a> to access your account';
exit();
}
// Place Session variable 'id' into local variable
$id = $_SESSION['id'];
// Process the form if it is submitted
if ($_FILES['uploadedfile']['tmp_name'] != "") {
// Run error handling on the file
// Set Max file size limit to somewhere around 120kb
$maxfilesize = 400000;
// Check file size, if too large exit and tell them why
if($_FILES['uploadedfile']['size'] > $maxfilesize ) {
echo "<br /><br />Your image was too large. Must be 400kb or less, please<br /><br />
<a href=\"upload_comic.php\">click here</a> to try again";
unlink($_FILES['uploadedfile']['tmp_name']);
exit();
// Check file extension to see if it is .jpg or .gif, if not exit and tell them why
} else if (!preg_match("/\.(gif|jpg|png)$/i", $_FILES['uploadedfile']['name'] ) ) {
echo "<br /><br />Your image was not .gif, .jpg, or .png and it must be one of those three formats.<br />
<a href=\"upload_comic.php\">click here</a> to try again";
unlink($_FILES['uploadedfile']['tmp_name']);
exit();
// If no errors on the file process it and upload to server
} else {
// Rename the pic
$newname = ""; //numbers only, so they show up sequentially
// Set the direntory for where to upload it, use the member id to hit their folder
// Upload the file
if (move_uploaded_file($_FILES['uploadedfile']['tmp_name'], "comics/$comicid/".$newname)) {
echo "Success, the image has been uploaded and will display to visitors!<br /><br />
<a href=\"member_account.php\">Click here</a> to return to your profile edit area";
exit();
} else {
echo "There was an error uploading the file, please try again. If it continually fails, contact us by email. <br /><br />
<a href=\"member_account.php\">Click here</a> to return to your profile edit area";
exit();
}
} // close else after file error checks
} // close if post the form
?>
理想情况下,我希望能够上传这样的图像:comics/comic_id/chapter_id/uploaded_file.extension
使用用户个人资料图片上传器,我能够从 $_Session['id'] 变量中获取 $ID,但是对于漫画,我真的不知道如何获取该信息并使用它来设置 Comic_id 目录(chapter_id 将在表格中选择,所以我不太担心那个)。
有什么想法吗?