图片上传到数据库未保存在目录中

时间:2019-03-22 01:19:23

标签: php html file-upload path image-uploading

我正在尝试将一些带有图像和视频的新课程添加到我的数据库中。我之前做过,但成功了,但是后来我创建了一个新项目,并将旧项目中的所有文件夹复制/粘贴到其中,这没用。

HTML

<html>
<div class="main-content">
  <div class="section__content section__content--p30">
    <div class="container-fluid">


      <div class="col-lg-12">
        <div class="card">
          <div class="card-header">
            <strong>Basic Form</strong> Elements
          </div>
          <div class="card-body card-block">
            <form action="index.php?admin=addcourse1" method="post" enctype="multipart/form-data" class="form-horizontal">

              <div class="row form-group">

                <div class="col-12 col-md-9">
                  <input type="hidden" name="courseID" class="form-control">
                </div>
              </div>

              <div class="row form-group">
                <div class="col col-md-3">
                  <label for="file-input" class=" form-control-label">Icon</label>
                </div>
                <div class="col-12 col-md-9">
                  <input type="file" id="fileToUpload" name="courseIcon" class="form-control-file">
                </div>
              </div>

              <div class="row form-group">
                <div class="col col-md-3">
                  <label for="text-input" class=" form-control-label">Title</label>
                </div>
                <div class="col-12 col-md-9">
                  <input type="text" id="text-input" name="courseTitle" placeholder="Text" class="form-control">
                </div>
              </div>

              <div class="row form-group">
                <div class="col col-md-3">
                  <label for="textarea-input" class=" form-control-label">Description</label>
                </div>
                <div class="col-12 col-md-9">
                  <textarea name="courseDesc" id="textarea-input" rows="9" placeholder="Content..." class="form-control"></textarea>
                </div>
              </div>

              <div class="row form-group">
                <div class="col col-md-3">
                  <label for="file-input" class=" form-control-label">Video</label>
                </div>
                <div class="col-12 col-md-9">
                  <input type="file" id="fileToUpload" name="courseVideo" class="form-control-file">
                </div>
              </div>

              <div class="row form-group">
                <div class="col col-md-3">
                  <label for="textarea-input" class=" form-control-label">Video Description</label>
                </div>
                <div class="col-12 col-md-9">
                  <textarea name="courseVideoDesc" id="textarea-input" rows="9" placeholder="Content..." class="form-control"></textarea>
                </div>
              </div>

              <div class="row form-group">
                <div class="col col-md-3">
                  <label for="text-input" class=" form-control-label">Tagline</label>
                </div>
                <div class="col-12 col-md-9">
                  <input type="text" id="text-input" name="courseTagline" placeholder="Text" class="form-control">
                </div>
              </div>

              <div class="row form-group">
                <div class="col col-md-3">
                  <label for="file-input" class=" form-control-label">Image</label>
                </div>
                <div class="col-12 col-md-9">
                  <input type="file" id="fileToUpload" name="courseImage" class="form-control-file">
                </div>
              </div>

              <div class="row form-group">
                <div class="col col-md-3">
                  <label for="textarea-input" class=" form-control-label">Information</label>
                </div>
                <div class="col-12 col-md-9">
                  <textarea name="courseInfo" id="textarea-input" rows="9" placeholder="Content..." class="form-control"></textarea>
                </div>
              </div>

              <div class="row form-group">
                <div class="col col-md-3">
                  <label for="text-input" class=" form-control-label">Price</label>
                </div>
                <div class="col-12 col-md-9">
                  <input type="text" id="text-input" name="coursePrice" placeholder="Text" class="form-control">
                </div>
              </div>




              <div class="card-footer">
                <button type="submit" class="btn btn-primary btn-sm">
                                            <i class="fa fa-dot-circle-o"></i> Submit
                                        </button>
                <button type="reset" class="btn btn-danger btn-sm">
                                            <i class="fa fa-ban"></i> Reset
                                        </button>
              </div>
            </form>
          </div>
        </div>
      </div>
    </div>
  </div>
</div>

</html>

PHP

<?php
include "dbconfig.php";

//icon
$folder ="courses_uploads/"; 

$courseIcon = $_FILES['courseIcon']['name']; 
$path = $folder . $courseIcon ;
$target_file=$folder.basename($_FILES["courseIcon"]["name"]);
$imageFileType=pathinfo($target_file,PATHINFO_EXTENSION);

 
$allowed=array('jpeg','png' ,'jpg');
$filename=$_FILES['courseIcon']['name'];
$ext=pathinfo($filename, PATHINFO_EXTENSION); 




//video
$courseVideo = $_FILES['courseVideo']['name']; 
$path2 = $folder . $courseVideo ;
$target_file2=$folder.basename($_FILES["courseVideo"]["name"]);
$imageFileType2=pathinfo($target_file2,PATHINFO_EXTENSION);

 
$allowed2=array('mp3','mp4' ,'wma'); 
$filename2=$_FILES['courseVideo']['name'];
$ext2=pathinfo($filename2, PATHINFO_EXTENSION); 





//image
$courseImage = $_FILES['courseImage']['name']; 
$path1 = $folder . $courseImage ;
$target_file1=$folder.basename($_FILES["courseImage"]["name"]);
$imageFileType1=pathinfo($target_file1,PATHINFO_EXTENSION);

 
$allowed1=array('jpeg','png' ,'jpg');
$filename1=$_FILES['courseImage']['name'];
$ext1=pathinfo($filename1, PATHINFO_EXTENSION); 







$stmt = $db_con->prepare("INSERT INTO db_course VALUES (:courseID, :courseIcon, :courseTitle, :courseDesc, :courseVideo, :courseVideoDesc, :courseTagline, :courseImage, :courseInfo, :coursePrice)");
$stmt->bindParam(":courseID", $_POST['courseID']);
$stmt->bindParam(":courseIcon", $courseIcon);
$stmt->bindParam(":courseTitle", $_POST['courseTitle']);
$stmt->bindParam(":courseDesc", $_POST['courseDesc']);
$stmt->bindParam(":courseVideo", $courseVideo);
$stmt->bindParam(":courseVideoDesc", $_POST['courseVideoDesc']);
$stmt->bindParam(":courseTagline", $_POST['courseTagline']);
$stmt->bindParam(":courseImage", $courseImage);
$stmt->bindParam(":courseInfo", $_POST['courseInfo']);
$stmt->bindParam(":coursePrice", $_POST['coursePrice']);


if ($stmt->execute() && in_array($ext,$allowed) && in_array($ext1,$allowed1) && in_array($ext2,$allowed2)) {

	move_uploaded_file( $_FILES['courseIcon'] ['tmp_name'], $path);
	move_uploaded_file( $_FILES['courseVideo'] ['tmp_name'], $path2);
	move_uploaded_file( $_FILES['courseImage'] ['tmp_name'], $path1);
	 

	echo "<script>alert('Successful');document.location.href='index.php?admin=course';</script>";
}

else {
	echo "<script>alert('error');document.location.href='index.php?admin=addcourse';</script>";
}
?>

错误

问题是,当我单击添加按钮时,所有数据都保存到数据库中,但是图像和视频没有保存到创建的文件夹中。我做了一些研究,大多数答案都解释说这是由于许可而发生的,但是我已经更改了它,或者我做错了吗?

这是我更改的权限的图像:

Image

运行代码时,页面仅显示错误消息,但不知道如何解决。

1 个答案:

答案 0 :(得分:0)

您是否配置了NTFS权限?在您的屏幕截图上,它看起来像是SMB权限。

NTFS Permission window