Search code examples
phpuploadapache2raspbian

Raspbian : Apache server cannot upload any files


I'm running an apache2 - php5 server on a RaspberryPi. When i try to upload a file by a form, it appears that move_uploaded_file returns False, and the file is not uploaded, even if it's very small.

I already edited /etc/php5/apache2/php.ini as follows :

upload_tmp_dir ="/tmp"
upload_max_filesize = 200G
max_file_uploads = 200
post_max_size = 10G

My html form must be correct since the upload system works perfectly on WAMP ! So I really don't understand what the issue is...

Does someone know why move_uploaded_file returns False, and why the server can't upload any files ?

Here is the code related to move_uploaded_file :

<?php
    if (isset($_POST['user_file'])) { //Upload file submit button pressed
        if ($_FILES['user_file']['error'] > 0) {echo "File could not be transfered";}
        $file_moved_ok = move_uploaded_file($_FILES['user_file']['tmp_name'], $_FILES['user_file']['name']);

        if ($file_moved_ok) {
            echo "<p>File uploaded alright</p>";
        } else {echo "<p>___File was NOT uploaded___</p>";}}
?>

Solution

  • move_uploaded_file will move the temp uploaded file from temp location to the destination you choose. you did not set destination directory. for example:

    move_uploaded_file($_FILES['user_file']['tmp_name'], '/detention_full_path/'.$_FILES['user_file']['name'];
    

    also, make sure the destination directory (/detention_full_path/) have write permission.