这是名为upload.php的文件
<?php
$con = mysqli_connect("localhost", "root", "", "tada");
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$file_name = basename($_FILES['0xfile']['name']);
$random_digit = rand(00000000, 99999999);
$allowed = array('png', 'jpg', 'PNG', 'JPG', 'jpeg');
$ext = pathinfo($file_name, PATHINFO_EXTENSION);
$new_file_name = $random_digit.".".$ext; //.$file_name;
$path = "./a/".$new_file_name;
if (!in_array($ext, $allowed)) {
echo 'Upload only .png or .jpg file';
} else {
if ($_FILES['0xfile']['size'] != 0) {
if (copy($_FILES['0xfile']['tmp_name'], $path)) {
echo "Successful<BR/>";
echo "File Name :".$new_file_name."<BR/>";
echo "File Size :".$_FILES['0xfile']['size']."<BR/>";
echo "File Type :".$_FILES['0xfile']['type']."<BR/>";
echo "File URL :"."./a/{$new_file_name}";
$url = "./a/{$new_file_name}";
echo "<br/><img src=\"{$url}\"/><br/>";
// Perform a query, check for error
if (!mysqli_query($con, "INSERT INTO upload_img(id,url) VALUES (NULL,'$url')")) {
echo "Error description: " . mysqli_error($con);
}
echo "Successful saved into database";
mysqli_close($con);
} else {
echo "Error";
}
}
}
这是Submit.php
<?php
// Initialize the session
session_start();
// Check if the user is logged in, otherwise redirect to login page
if(!isset($_SESSION["loggedin"]) || $_SESSION["loggedin"] !== true){
header("location: login.php");
exit;
}
?>
<table width="500" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<form action="upload.php" method="post" enctype="multipart/form-data" name="form1" id="form1">
<td>
<table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
<tr>
<td><strong>Image File Upload </strong></td>
</tr>
<tr>
<td>Moha <input name="0xfile" type="file" id="0xfile" size="50" /></td>
</tr>
<tr>
<td align="center"><input type="submit" name="Submit" value="Upload" /></td>
</tr>
</table>
</td>
</form>
</tr>
</table>
在过去两个小时里,我用谷歌搜索,但是没有找到任何东西,我尝试了一些东西,但是没有任何效果,我想我没有尝试所有东西。那么,如何将它们组合成一个脚本,一个简单易懂的脚本呢? 预先感谢
(对于这一重复,我感到抱歉,但是它告诉我添加更多详细信息,在过去两个小时里,我用Google搜索时没有更多详细信息,但是我什么也没找到,我尝试了一些东西,但是什么也没做我想我并没有尝试一切,所以如何将它们组合成一个脚本,一个简单易懂的脚本? 提前谢谢)