1

I have a server apache and mysql at my friend's house, i can connect to both of them, but i want to upload pictures from my Macbook to my directory in the server (Ubuntu), i have some issues and tried many things but any of them worked, please help me thanks :)

The html form:

<html>
        <head>
        </head>

        <body>
                <form accept-charset="UTF-8" action="php.php" method="POST" enctype="multipart/form-data">
                        <input type="file" name="img"/>
                        <input type="submit"/>
                </form>
        </body>

</html>

The php :

    <html>

<head> <meta charset="UTF-8"/> </head>

</html>


<?php


$bdd = new PDO('mysql:host=***.***.***.***;port:****;dbname=**********', '*******', '**********',array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));


echo $_FILES['img']['name'];

$target1 = "/home/knight/";
$target = $target1 . basename( $_FILES['img']['name']);

if(move_uploaded_file($_FILES['img']['tmp_name'], $target))
{

//Tells you if its all ok
echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded, and your information has been added to the directory";
}
else {

//Gives and error if its not
echo "Sorry, there was a problem uploading your file.";
}
?>
  • So tell us what you tried so we dont waste time suggesting the same things. Also have you looked at the apache and php error logs on the server. They may tell you a lot. – RiggsFolly Jun 18 '15 at 12:43
  • Lets assume that you gave access to apache user to write on your home folder `/home/knight/`. Is this what you want? because almost everyone have right to write on your home folder. – Mehdi Jun 18 '15 at 12:45
  • The upload directory must be 777 writable. What exactly is your error? – pbu Jun 18 '15 at 12:46
  • copy this into your code and tell us the error error_reporting(-1); ini_set('display_errors', 'On'); – SpongePablo Jun 18 '15 at 12:48
  • I tried without the PDO, with another directory, with another file, changing the name of input name, and look for answer around internet but i didn't find anything :/ – Ben Thirouard Jun 18 '15 at 12:48
  • you dont need pdo as you ar enot using a DB – SpongePablo Jun 18 '15 at 12:51
  • check with this function if the file is uploaded and tell us the result is_uploaded_file($_FILES['img']['tmp_name']); – SpongePablo Jun 18 '15 at 12:54
  • With the error reporting and quoting the line with the PDO, it's telling me: Notice: Undefined index: img in /var/www/html/tewt/php.php on line 18 Notice: Undefined index: img in /var/www/html/tewt/php.php on line 20 – Ben Thirouard Jun 18 '15 at 12:56
  • Other users had this problem before. Please check this [link][1] or [this one][2]. [1]: http://stackoverflow.com/questions/18747542/notice-undefined-index-image-unable-to-find-the-error [2]: http://stackoverflow.com/questions/18887004/undefined-index-in-file-while-uploading-image – SpongePablo Jun 18 '15 at 13:03

0 Answers0