我想上传然后将视频移动到刚刚创建的目录中。它不会将视频移动到 /var/www/html/ProductVideos/lazar108@hotmail.com ,而是将视频发送到 / var / www / html / ProductVideos /
如果我制作$ location =" /var/www/html/ProductVideos/lazar108@hotmail.com"但是位置会改变,所以我试图让PHP脚本动态
ProductAccountName = lazar108@hotmail.com
PHP代码:
<?php
$ProductAccountName = $_POST['ProductAccountName'];
$NewDirectory = "/var/www/html/ProductVideos/" . $ProductAccountName;
if (!file_exists($NewDirectory))
{
mkdir($NewDirectory, 0777, true);
}
if($_SERVER['REQUEST_METHOD']=='POST'){
$file_name = $_FILES['myFile']['name'];
$file_size = $_FILES['myFile']['size'];
$file_type = $_FILES['myFile']['type'];
$temp_name = $_FILES['myFile']['tmp_name'];
$location = $NewDirectory . $file_name; //"/var/www/html/ProductVideos/$ProductAccountName/" . $file_name;
move_uploaded_file($temp_name, $location);
答案 0 :(得分:1)
可能未设置$_POST['ProductAccountName']
,因此请遵循代码
$ProductAccountName = $_POST['ProductAccountName'];
$NewDirectory = "/var/www/html/ProductVideos/" . $ProductAccountName;
导致$ProductAccountName
为空。确保添加
<input type="text" name="ProductAccountName" value="lazar108@hotmail.com">
在HTML表单中。
答案 1 :(得分:0)
我认为在创建/
变量后$ProductAccountName
之后没有$NewDirectory
。像这样尝试rewerite location
:
$location = $NewDirectory . '/' . $file_name;