user3701575
user3701575

Reputation: 5

move_uploaded_files() php is not moving the file

So I have a bit of a problem. I was looking at a tutorial for video uploads and I came across this tutorial.

https://www.youtube.com/watch?v=SibODOJle6Q

It seems that my move_uploaded_files is not working and it is trivial for me to see his code work which I copied and the result is completely different.

Could I get some help with this please?

my Code below

<html>
<head>
<title>Video Upoad</title>
<link rel='stylesheet' href='stylesheet.css'/>
</head>
<body>
    <?php 
    require('connect.php');
    ?>

    <div id='box'>
        <form method ='post' enctype='multipart/form-data'>
            <?php
            if(isset($_FILES['video'])){

                $name= $_FILES['video']['name'];
                $type = explode('.',$name);
                $type=end($type);
                $size= $_FILES['video']['size'];
                $random_name=rand();
                $tmp = $_FILES['video']['tmp_name'];

                if($type !='mp4' && $type != 'MP4' && $type!='flv'){
                    $message = "Video Format is not supported!";


                }else{
                    move_uploaded_file($tmp, 'viddata/'.$random_name.'.'.$type);
                    $message ="The Upload was successful";
                    mysql_query("INSERT INTO video VALUES ('','$name','viddata/$random_name.$type')");

                }
                echo $message.'<br/><br/>';
                //echo $type.'<br/>';
                //echo $name.'<br/>';
            }


?>


            Select Video: <br/>
            <input type='file' name='video' />
            <br/><br/>
            <input type='submit' value='Upload' />
        </form>
    </div>

    <div id='box'>
    </div>
</body>

</html>

It does insert into the database and everything except moving the file to the destination.

Upvotes: 0

Views: 117

Answers (2)

Rudiger W.
Rudiger W.

Reputation: 868

Start by checking the return value, errors and warnings. The documentation says:

Return Values


Returns TRUE on success.

If filename is not a valid upload file, then no action will occur, and move_uploaded_file() will return FALSE.

If filename is a valid upload file, but cannot be moved for some reason, no action will occur, and move_uploaded_file() will return FALSE. Additionally, a warning will be issued.

There are also some good examples with more comprehensive error checking.

Upvotes: 1

Logan Wayne
Logan Wayne

Reputation: 5991

You should consider the following:

  • Make sure you have viddata folder.
  • Check the file size of the file you are trying to upload if it exceeds the upload_max_filesize.
  • If it does, you can configure your php.ini and set the upload_max_filesize to your preferred size, then reset your XAMPP Control Panel.
  • Check also the permission of the folder/directory you are trying to upload the file.
  • You should also set conditions on the files being uploaded by the user, like setting the condition for file type and size before you upload process it.

Upvotes: 1

Related Questions