简体   繁体   English

文件上传在WAMP服务器上不起作用?

[英]File upload not working on wamp server?

I am working on a project where you have to upload all files on a server in JPEG format but this following code in upload.php is not working, like it is not checking the condition whether there is a name to album or not. 我正在一个项目中,您必须以JPEG格式上载服务器上的所有文件,但是upload.php中的以下以下代码不起作用,就像它没有检查条件是否为相册命名。

Following file is upload.php with database connect to it with 4 fields in table... id , name , album_id , url . 接下来的文件是带有数据库的upload.php,它通过表中的4个字段连接到它: idnamealbum_idurl

<html>
<head>
<title>PHP file upload</title>
<link rel="stylesheet" href="style.css" />
</head>
<body>
<?php include 'connect.php'; ?>
<div id="body">
  <?php include 'title_bar.php'; ?>
    <div id="container">
    <h3>Upload</h3>
    <form enctype="multipart/form-data" method="POST">

        <?php

        if (isset($_POST['upload'])) {
            $name = $_POST['name'];
            $album_id = $_POST['album'];
            $file = $_FILES['file']['name'];
            $file_type = $_FILES['file']['type'];
            $file_size = $_FILES['file']['size'];
            $file_tmp = $_FILES['file']['tmp_name'];

            if(empty($name) || empty($file)){
                echo "Please Fill ALL THE FUIELD ";
            }else{
                echo "working";
            }
        }



        ?>
        Name : <br />
        <input type="text" name="name" />
        <br  /> <br  />
        Select Folder : <br />
        <select>
            <?php 
                $query = mysql_query("SELECT id , name FROM albums");
                while($run = mysql_fetch_array($query)){
                    $album_id = $run['id'];
                    $album_name = $run['name'];
                    echo "<option value='$album_id'> $album_name </option>";
                }
            ?>
        </select>
        <br /><br />
        Select File : <br />
        <input type="file" name="file" />
        <br /> <br />
        <input type="submit" name="Upload" value="Upload" />
    </form>
    </div>
</div>

</body>
</html>

文件类型和大小尚未定义,上传配置数组未初始化

The keys in $_POST are case-sensitive, you're checking for Upload but your input name is upload . $_POST中的键区分大小写,您要检查Upload但输入名称是upload

You should either change your input to : 您应该将input更改为:

<input type="submit" name="upload" value="Upload" />

Or your first PHP check to : 或您的第一个PHP检查到:

if (isset($_POST['Upload'])) {

Also, you should set a name attribute for your select or it won't be sent. 另外,您应该为您的select设置name属性,否则将不发送该属性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM