Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/260.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
上载文件时,php数组文件为空_Php - Fatal编程技术网

上载文件时,php数组文件为空

上载文件时,php数组文件为空,php,Php,当我上传文件时,它显示数组文件为空,但在我的php.ini中,上传是打开的 请查看我的代码并告诉我错误在哪里 我在网上到处寻找解决方案,但没有找到,我在centos 5.4内核版本2.6.18-164.el5上使用PHP版本5.3.25 谢谢和问候 哈迪 html页面 <!DOCTYPE html> <head> <title>MySQL file upload example</title> <meta http-equiv="conten

当我上传文件时,它显示数组文件为空,但在我的php.ini中,上传是打开的

请查看我的代码并告诉我错误在哪里

我在网上到处寻找解决方案,但没有找到,我在centos 5.4内核版本2.6.18-164.el5上使用PHP版本5.3.25

谢谢和问候

哈迪

html页面

<!DOCTYPE html>
<head>
<title>MySQL file upload example</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
</head>
<body>
<form action="add_file.php" method="post" enctype="multipart/form-data">
    <input type="file" name="uploaded_file"><br>
    <input type="submit" value="Upload file">
</form>
<p>
    <a href="list_files.php">See all files</a>
</p>
</body>
</html>

MySQL文件上传示例

add_file.php

<?php
// Check if a file has been uploaded
if(isset($_FILES['uploaded_file'])) {
    // Make sure the file was sent without errors
    if($_FILES['uploaded_file']['error'] == 0) {
        // Connect to the database
        $dbLink = new mysqli('127.0.0.1', 'user', 'pwd', 'myTable');
        if(mysqli_connect_errno()) {
            die("MySQL connection failed: ". mysqli_connect_error());
        }

        // Gather all required data
        $name = $dbLink->real_escape_string($_FILES['uploaded_file']['name']);
        $mime = $dbLink->real_escape_string($_FILES['uploaded_file']['type']);
        $data = $dbLink->real_escape_string(
            file_get_contents($_FILES['uploaded_file']['tmp_name'])
        );
        $size = intval($_FILES['uploaded_file']['size']);

        // Create the SQL query
        $query = "
        INSERT INTO `file` (
            `name`, `mime`, `size`, `data`, `created`
        )
        VALUES (
            '{$name}', '{$mime}', {$size}, '{$data}', NOW()
        )";

        // Execute the query
        $result = $dbLink->query($query);

        // Check if it was successfull
        if($result) {
            echo 'Success! Your file was successfully added!';
        } else {
            echo 'Error! Failed to insert the file'
            . "<pre>{$dbLink->error}</pre>";
        }
    } else {
        echo 'An error accured while the file was being uploaded. '
        . 'Error code: '. intval($_FILES['uploaded_file']['error']);
    }

    // Close the mysql connection
    $dbLink->close();
} else {
    echo 'Error! A file was not sent!';
}

// Echo a link back to the main page
echo '<p>Click <a href="index.html">here</a> to go back</p>';
?>

所以你试图不使用I-see上传;这不是一个好主意。我们在哪里
move_upload_file
将其上载到服务器?@Fred我相信,因为他实际上不是将文件上载到服务器,而是存储在数据库中,所以他不一定要使用move upload file。hadi我相信问题在于,您实际上是在尝试将二进制数据转换为字符串。你不能那样做。如果要使用php将二进制数据插入数据库,必须先使用base64encode()之类的函数。@SethCohen是的,我注意到了。很多时候,我都在电视上看到大炮,说这不是一个好主意。