将图像上载到服务器不起作用

时间:2016-01-12 11:59:34

标签: php mysql

 <?
     if(isset($_POST['submit'])){
        $name       = $_FILES['photo']['name'];  
        $temp_name  = $_FILES['photo']['tmp_name'];  
        var_dump($_FILES);
        if(isset($name)){
            if(!empty($name)){ 
            var_dump($_FILES);     
                $location = '../images/';      
                if(move_uploaded_file($temp_name, $location.$name)){
                    echo 'File uploaded successfully';

                }
            }       
        }  else {
            echo 'You should select a file to upload !!';
        }
    }

    ?>
<form action="<? echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" method="post" enctype="multipart/form-data">
<input type="file" name="photo"/>
<input type="submit" value="Submit" name="submit"/>
</form>

这是我的代码,使用iis将我的图像上传到我的服务器,我没有错误,但图像没有上传。我还要将位置上传到mysql数据库,但我无法让它工作。我尝试上传一个大的形式,但它只是清除我的形式的所有帖子,它变得烦人现在哈哈两天试图让这个工作。 Folder Setup

2 个答案:

答案 0 :(得分:1)

<form action="<? echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" method="post" enctype="multipart/form-data">
<input type="file" name="photo"/>
<input type="submit" value="Submit" name="submit"/>
</form>
<?php
    //print_r($_POST);
     if(isset($_POST['submit'])){
       echo  $name       = $_FILES['photo']['name'];  
        $temp_name  = $_FILES['photo']['tmp_name'];  
        var_dump($_FILES);
        if(isset($name)){
            if(!empty($name)){ 
            var_dump($_FILES);     
                $location = '../images/'.$name;      
                if(move_uploaded_file($temp_name, $location)){
                    echo 'File uploaded successfully';

                }
            }       
        }  else {
            echo 'You should select a file to upload !!';
        }
    }

    ?>

答案 1 :(得分:0)

我的图片文件夹结构:C:\xampp\htdocs\test1\images,我试过这个并且它正在运行:

  <?php
  if(isset($_POST['submit']))
  {
    $name       = $_FILES['photo']['name'];
    $temp_name  = $_FILES['photo']['tmp_name'];
    if(isset($name)){
        if(!empty($name)){ 
            $location = 'images/';
            if(move_uploaded_file($temp_name, $location.$name)){
                echo 'File uploaded successfully';
            }
        }
    }  else {
        echo 'You should select a file to upload !!';
    }
}
?>
<form action="<? echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" method="post" enctype="multipart/form-data">
    <input type="file" name="photo"/>
    <input type="submit" value="Submit" name="submit"/>
</form>

我收到了消息: File uploaded successfully ,而且,我可以在该文件夹中找到该图片。