0

I have a problem loading the file to the server in PHP and HTML using move_uploaded_file () when I put PHP files in this way http://mydomin.com/uploadfile.php succeed the process and if this way http://mydomin.com/uploadfiles/uploadfile.php The the process fails

code php

<?php
if (isset($_FILES['image'])) {

    $idApp = uniqid();
    $uploadDir = '../images/';
    $uploadedFile = $uploadDir . $idApp . ".jpg";

    if(move_uploaded_file($_FILES['image']['tmp_name'], $uploadedFile)) {

    echo"Success: ".$_FILES['image']['tmp_name']. $uploadedFile;
    } else {

    echo"error 2";
    }

} else {

    echo"error 3";
}
?>

code html

<form action="add.php" method="POST" enctype="multipart/form-data">

    <input type='file' name='image' id='image'>
    <div align='center''><input type='submit' id='myButton' value='add'></div>";

</form>

2 Answers 2

1

check your upload path

$uploadDir = '../images/';

Try to use this path './images/' or best use absolute path.

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

3 Comments

Not working with me, but how to use the absolute path
The file in which my site is "/website/" and the file in which the PHP files upload the image in "/website/uploadfiles/ "and want to upload in "/website/images" I have used this code and succeeded the process ( $uploadDir = '../../website/images/';)
you can try FILE it will return a absolute path of the current file.
1

check your script location by using

var_dump(__DIR__)

this will show you where is your .php file is ( also called as absolute path ). Thus simply you can see where you made a mistake to assign a folder for file uploading(image in your case ).

Comments

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.