php upload image with form not working

后端 未结 2 679
臣服心动
臣服心动 2021-01-28 07:00

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:



        
相关标签:
2条回答
  • 2021-01-28 07:18

    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); 
    
    }
    
    ?>
    
    0 讨论(0)
  • 2021-01-28 07:40

    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' />";
    
    0 讨论(0)
提交回复
热议问题