1

i want to upload and then move a video to a directory i just created. Instead of moving the video to /var/www/html/ProductVideos/[email protected] it sends the video to /var/www/html/ProductVideos/

It works if i make $location = "/var/www/html/ProductVideos/[email protected]" but the location will change so i am trying to make the PHP script dynamic

ProductAccountName = [email protected]

Before PHP: enter image description here

After PHP: enter image description here

PHP code:

<?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);

2 Answers 2

1

Maybe $_POST['ProductAccountName'] is not set, so following code

$ProductAccountName = $_POST['ProductAccountName'];

$NewDirectory = "/var/www/html/ProductVideos/" . $ProductAccountName;

causes $ProductAccountName to be empty. Make sure you add

<input type="text" name="ProductAccountName" value="[email protected]">

inside your HTML form.

Sign up to request clarification or add additional context in comments.

4 Comments

well if that was the case then the new directory wouldnt be made
try print($location); just to make sure it points to correct directory.
i am actually not using HTML so i couldnt do that :/
This isnt the correct answer but it got me thinking and i figured it out myself
0

I think there is no / after $ProductAccountName in creating $NewDirectory variable. Try rewerite location like this:

$location = $NewDirectory . '/' . $file_name;

2 Comments

i think its something like that but that didnt fix it
So what is in $location variable?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.