我有2个上传字段,用于上传歌曲。 1)上传歌曲和2)上传图片。轻松上传歌曲而未在文件夹中上传图像。并且它甚至将其路径存储在数据库中,不仅上传到图像的特定文件夹。
以下是两个文件的代码。
UPLOAD-QUERY.PHP
<?php
include 'conf.php';
$title = $_POST['title'];
$artist = $_POST['artist'];
$category = $_POST['category'];
$language = $_POST['language'];
$uploadDir = 'http://localhost/PHP%20Learning/Music%20Player/'.'songs/';
$fileName = $_FILES['path']['name'];
$filePath = $uploadDir . $fileName;
$uploadiDir = 'http://localhost/PHP%20Learning/Music%20Player/'.'images';
$fileiName = $_FILES['ipath']['name'];
$fileiPath = $uploadiDir . $fileiName;
if(move_uploaded_file($_FILES["path"]["tmp_name"],"songs/".$_FILES["path"]["name"]) ||
move_uploaded_file($_FILES["ipath"]["tmp_name"],"songs/".$_FILES["ipath"]["name"])) {
mysqli_query($con, "INSERT INTO `audio` (`title`, `artist`, `category`, `language`,`path`, `ipath`) VALUES ('".$title."', '".$artist."', '".$category."', '".$language."', '".$filePath."', '".$fileiPath."')") or die(mysqli_error($con));
}
UPLOAD.PHP
<div class="row">
<div class="col-md-6">
<label><b>Select Audio to upload:</b></label></br></br>
<input type="file" name="path" style="border: 1px solid #f1f1f1;">
</div>
<div class="col-md-6">
<label><b>Select Image to upload:</b></label></br></br>
<input name="ipath" type="file" style="border: 1px solid #f1f1f1;">
</br></br>
</div>
</div>
<-----UPLOAD.PHP
答案 0 :(得分:-2)
最重要的事情请不要使用这类静态网址。而是动态使用基本URL,并将后面的部分附加到该URL。
为此,如果要进行测试或调试,则无需在行末使用“ /”:
我使用的是核心PHP的基本URL:
define( 'ABSPATH', dirname(dirname(__FILE__)) . '/' );
$uploadiDir = ABSPATH.'Learning/Music/Player/'.'images/';