我正在尝试使用php上传文件并将文件信息存储在数据库中。数据库部分工作正常,但我试图将文件移动到名为videos /的目录,但文件不会移动到此目录。这是我的PHP代码:
<?php
mysql_connect('localhost', 'root', '');
mysql_select_db('manchesterunited');
if(isset($_POST['submit']))
{
$name = $_FILES['file']['name'];
$temp = $_FILES['file']['tmp_name'];
move_uploaded_file($temp,"videos/".$name);
$url = "localhost/manchesterunited/videos/$name";
mysql_query("INSERT INTO video VALUES ('','$name','$url')");
}
?>
答案 0 :(得分:0)
尝试使用以下代码将“/ full / path / to /”替换为实际目录。通常这就像“/ home / username / public_html /”
if(isset($_POST['submit']))
{
$dir = '/full/path/to/manchesterunited/videos/';
$file = $dir . basename($_FILES['file']['name']);
$temp = $_FILES['file']['tmp_name'];
move_uploaded_file($temp,$file);
$url = "localhost/manchesterunited/videos/$name";
mysql_query("INSERT INTO video VALUES ('','$name','$url')");
}
?>