使用php将图片上传到服务器目录

时间:2015-06-18 12:41:07

标签: php image upload directory server

我的朋友家里有一台服务器apache和mysql,我可以连接到他们两个,但我想把我的Macbook上的图片上传到服务器上的目录(Ubuntu),我有一些问题并试了很多东西,但其中任何一个都有效,请帮助我谢谢:)。

html表单:

<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>

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.";
}
?>

0 个答案:

没有答案