php上传图片,表单不起作用

时间:2014-12-08 16:33:45

标签: php html image forms upload

我对其他人对同一问题的威胁提出了很多建议,但他们没有成功。 谁能看到我做错了什么?

我的表格的一部分:

<form id="register-Form" name="register-Form" method="post" enctype="multipart/form-data"     action="exec.php">

<div class="register-line">
   <div class="ricon"><i class="fa fa-male"></i> </div> 
    picture
    <input id="file" type="file" name="file" class="register-text">  </input>
</div>

exec.php代码

$target_path = "/images/";

$target_path = $target_path . basename( $_FILES['file']['name']); 

if(move_uploaded_file($_FILES['file']['tmp_name'], $target_path)) {
 //succes
} else{
//nothing
}

2 个答案:

答案 0 :(得分:0)

试试这个

<?php include('connect.php');

$uploadDir = '/pictures/';

if(isset($_POST['submit']))
{
$fileName = $_FILES['file']['name'];
$tmpName  = $_FILES['file']['tmp_name'];
$fileSize = $_FILES['file']['size'];
$fileType = $_FILES['file']['type'];

$filePath = $uploadDir . $fileName;

$result = move_uploaded_file($tmpName, $filePath);
if (!$result) {
echo "Error uploading <strong>file</strong>";
exit;
}

if(!get_magic_quotes_gpc())
{
    $fileName = addslashes($fileName);
    $filePath = addslashes($filePath);
}

$title = $_POST['title'];
$description = $_POST['description'];

$query = "INSERT INTO ".$user_pictures." (file, title, description) VALUES ('".$filePath."', '".$title."', '".$description."')";

mssql_query($query); 

}

?>

答案 1 :(得分:0)

尝试使用此代码

$temp = $_FILES["file"]["tmp_name"];
$image = basename($_FILES["file"]["name"]);
$img = "images/".$image;
move_uploaded_file($temp, $img);
echo "<img src=images/".$image' />";