在我的网站上,我有 2 个不同的地方供用户上传图片。第一个完美运行。第二个没有。据我所知,它们完全相同。为了测试,我在两者上都使用了相同的图像,它适用于第一个,但不是第二个。这是非工作代码的代码:
<?php
include('cn.php');
$name = $_FILES['image']['name'];
$type = $_FILES['image']['type'];
$size = $_FILES['image']['size'];
$temp = $_FILES['image']['tmp_name'];
$error = $_FILES['image']['error'];
echo $name; //Doesnt echo anything
$rand_num = rand(1, 1000000000);
$name = $rand_num . "_" . $name;
echo $name; //Echos just the random number followed by _
if ($error > 0) {
die("Error uploading file! Go back to the <a href='gallery.php'>gallery</a> page and try again.");
} else {
$sql = "INSERT INTO gallery (image) VALUES ('".$name."')"; //Inserts the random number to the database
$query = mysql_query($sql) or die(mysql_error());
echo $sql;
move_uploaded_file($temp, "gallery_pics/$name"); //Doesn't move the file. gallery_pics exists, if that matters
echo "Upload complete! Go back to the <a href='gallery.php'>album</a>.";
}
?>
如果有人可以请在这里帮助我。我确信这很简单,但我还没有找到任何有帮助的东西。谢谢!
编辑:代码上方有两行无法正确显示。一个启动php,另一个打开数据库。