php upload image with form not working

烂漫一生 提交于 2019-12-02 20:20:14

问题


I tried a lot suggestions at other people's threats about the same problem, but they didn't work. Can anyone see what I'm doing wrong?

Part of my form:

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

$target_path = "/images/";

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

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

回答1:


try with this code

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



回答2:


try this

<?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); 

}

?>


来源:https://stackoverflow.com/questions/27362482/php-upload-image-with-form-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!