I am a beginning in Php.
I have been trying for several hours to move an uploaded image to a directory without success. I have already read other questions about the subject, but I have not been able to solve the problem:
1) I have already checked if the directory exists (see output below);
2) It seems that the directory is not writable, but I am not only trying to save the image in a kind of system directory, but also in a simple directory of my computer.
3) The image seems to be uploaded correctly.
4) I have already used "sudo chmod -R 775 /home/daniel/NetBeansProjects/NewPhpProject/photos", but this should not be the problem, since this is not a system directory!
I have no idea what is happening.
Daniel
See my code below:
uploadImage.php
<html>
    <body>
        <h2> Upload your photo. </h2>
        <form action="moveImage.php" method="post"
              enctype="multipart/form-data">
            <label for="file">Filename:</label>
            <input type="file" name="file" id="file"><br>
            <input type="submit" name="submit" value="Submit">
        </form>
    </body>
</html>
movingImage.php
    <?php
    if ($_FILES["file"]["error"] > 0) {
        echo "Error: " . $_FILES["file"]["error"] . "<br>";
    } else {
        //$upload_dir = $_SERVER['DOCUMENT_ROOT'] . "/photos/";
        //$upload_dir = dirname(__FILE__) . "/photos/";
        $upload_dir ="/home/daniel/NetBeansProjects/NewPhpProject". "/photos/";
        echo "upload_dir: " . $upload_dir . "<br>";
        if (file_exists($upload_dir)) {
            if (is_writable($upload_dir)) {
                $target = $upload_dir; //"dirname(__FILE__)" . "photos/";
                $target = $target . basename($_FILES['file']['name']);
                $moved = move_uploaded_file($_FILES['file']['name'], "$target");
            } else {
                echo 'Upload directory is not writable<br>';
            }
        } else {
            echo 'Upload directory does not exist.<br>';
        }
        echo $target . "<br>";
    //  echo dirname(__FILE__)."<br>";
    echo "Upload: " . $_FILES["file"]["name"] . "<br>";
    echo "Type: " . $_FILES["file"]["type"] . "<br>";
    echo "Size: " . ($_FILES["file"]["size"] / 1024) . " kB<br>";
    echo "Stored in: " . $_FILES["file"]["tmp_name"];
}
?> 
Output:
upload_dir: /home/daniel/NetBeansProjects/NewPhpProject/photos/
Upload directory is not writable
Upload: FotoCaju.jpeg
Type: image/jpeg
Size: 0.666015625 kB
Stored in: /tmp/phpmTJWMi
 
     
     
    