我正在尝试使用PHP将歌曲上传到数据库,就像soundcloud web一样。但它给了我错误
注意:未定义的索引:第25行的C:\ Xampp \ htdocs \ aksongs \ upload.php中的文件
注意:未定义的索引:第26行的C:\ Xampp \ htdocs \ aksongs \ upload.php中的文件
这是文件代码
<?php
include_once 'connection.php';
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>AK music</title>
<link rel="stylesheet" href="main.css" href="main.js" >
</head>
<body>
<form enctype="multipart/form-data" action="upload.php" method="POST">
Please choose a file: <input name="file" type="file" /><br />
<input type="submit" value="submit" />
</form>
<?php
$name = $_FILES['file']['name'];
$tmp_name = $_FILES['file']['tmp_name'];
if(isset($name)){
if(!empty($name)){
$location = 'aksongs/upload';
if(move_uploaded_file($tmp_name,$location.$name)){
echo 'uploaded';
}
}else{
echo 'Please choose a file';
}
}
?>
</body>
</html>
&#13;
答案 0 :(得分:0)
您的代码应该是这样的
<?php if(isset($_FILES['file']['name']) && $_FILES['file']['name']!=''){
$name = $_FILES['file']['name'];
$tmp_name = $_FILES['file']['tmp_name'];
if(!empty($name)){
$location = 'aksongs/upload';
if(move_uploaded_file($tmp_name,$location.$name)){
echo 'uploaded';
}
}else{
echo 'Please choose a file';
}}else{
echo 'Please choose a file';
} ?&GT;