簡體   English   中英

無法在PHP,MySql中上傳3mb +文件

[英]Can't Upload 3mb+ Files in PHP, MySql

我可以上傳小於3 mb的文件,但不能通過編碼上傳3mb +的文件。 :/我進行了搜索,並更改了upload_max_filesize = 64M和post_max_size = 128M仍然遇到相同的錯誤。錯誤為“錯誤!未發送文件!” 這是由我設置的:P,這是我的編碼,請幫助我.....在此先感謝:)

數據庫查詢

CREATE TABLE `file` (
`id`        Int Unsigned Not Null Auto_Increment,
`name`      VarChar(255) Not Null Default 'Untitled.txt',
`mime`      VarChar(50) Not Null Default 'text/plain',
`size`      BigInt Unsigned Not Null Default 0,
`data`      MediumBlob Not Null,
`created`   DateTime Not Null,
PRIMARY KEY (`id`)
)

Index.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>

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', 'root', '', 'cart');
       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>';
?>

更改upload_max_filesize = 64M和post_max_size = 128M后,我需要重新啟動服務器,然后編碼才能正常工作。 :)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM