简体   繁体   English

PHP move_uploaded_file无法将视频上传到MySQL

[英]PHP move_uploaded_file to upload video into MySQL not working

I want to upload a video into my server, right now I'm testing locally using XAMPP in my Macbook. 我想将视频上传到服务器中,现在我正在Macbook中使用XAMPP在本地进行测试。 I've a column named "path" in my database, this is meant to store the path and name of the file. 我的数据库中有一列名为“ path”的列,用于存储文件的路径和名称。 After my code ends it saves a $path into the path column this part works perfectly, yet it doesn't moves the file. 我的代码结束后,它将$ path保存到path列中,该部分可以正常运行,但不会移动文件。

I've already given 777 permissions to the folder and it still doesn't move the file, and of course my PHP file is in the same folder as my destination in this case "material/videos/" 我已经授予该文件夹777权限,但它仍然不会移动该文件,当然,在这种情况下,“ PHP /我的PHP /文件”与目标文件夹位于同一文件夹中,即“ material / videos /”

This is how my code looks. 这就是我的代码的样子。

` `

<?php

function uploadVideo($target_dir, $id1) {

$allowedExts = array("jpg", "jpeg", "gif", "png", "mp3", "mp4", "wma");
$extension = pathinfo($_FILES['file']['name'], PATHINFO_EXTENSION);

if ((($_FILES["file"]["type"] == "video/mp4")
|| ($_FILES["file"]["type"] == "audio/mp3")
|| ($_FILES["file"]["type"] == "audio/wma")
|| ($_FILES["file"]["type"] == "image/pjpeg")
|| ($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg"))

&& ($_FILES["file"]["size"] < 500000000)
&& in_array($extension, $allowedExts))

  {
  if ($_FILES["file"]["error"] > 0)
    {
    echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
    }
  else
    {
    echo "Upload: " . $_FILES["file"]["name"] . "<br />";
    echo "Type: " . $_FILES["file"]["type"] . "<br />";
    echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
    echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";

    if (file_exists("material/videos/" . $_FILES["file"]["name"]))
      {
      echo $_FILES["file"]["name"] . " already exists. ";
      }
    else
      {
// EVEN THOUGH THIS IS IN SAME ELSE CONDITION THE MOVE IS NOT DONE
      move_uploaded_file($_FILES["file"]["tmp_name"], "material/videos/");
      echo "Stored in: " . "material/videos/" . $_FILES["file"]["name"];

//HERE IS WHERE I RETURN $PATH CORRECTLY TO SAVE IT INTO DATABASE
      $path = "material/videos/" . $_FILES["file"]["name"];
      return $path;
      }
    }
  }
else
  {
  echo "Invalid file";
  }
}

?>`

you have to specify the whole path in move_uploaded_file . 您必须在move_uploaded_file指定整个路径。 This includes the new filename. 这包括新的文件名。 ie: 即:

move_uploaded_file($_FILES["file"]["tmp_name"], "material/videos/".$_FILES["file"]["name"]);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM