gpt4 book ai didi

php - 上传图像 php mysql 二进制文件

转载 作者:行者123 更新时间:2023-11-30 23:32:18 24 4
gpt4 key购买 nike

大家好,当我尝试上传时,我总是收到一个错误,没有选择图像,上传表单的名称和 ID 肯定是正确的,所以一定是代码有问题,有人能看出原因吗?

<?php


// Create MySQL login values and
// set them to your login information.
$username = "**";
$password = "**";
$host = "**";
$database = "**";

// Make the connect to MySQL or die
// and display an error.
$link = mysql_connect($host, $username, $password);
if (!$link) {
die('Could not connect: ' . mysql_error());
}

// Select your database
mysql_select_db ($database);

session_start();
if(!isset($_SESSION['username']))
{
die('You have no access to this page.');
}
else{
$username = $_SESSION['username'];
// Make sure the user actually
// selected and uploaded a file
if (isset($_FILES['image']) && $_FILES['image']['size'] > 0) {

// Temporary file name stored on the server
$tmpName = $_FILES['image']['tmp_name'];

// Read the file
$fp = fopen($tmpName, 'r');
$data = fread($fp, filesize($tmpName));
$data = addslashes($data);
fclose($fp);


// Create the query and insert
// into our database.
$query = "INSERT INTO Members WHERE username = '$username' ";
$query .= "(image) VALUES ('$data')";
$results = mysql_query($query, $link);

// Print results
print "Thank you, your file has been uploaded.";

}
else {
print "No image selected/uploaded";
}
}
// Close our MySQL Link
mysql_close($link);
?>

最佳答案

可能是你的 <form>标签缺少 enctype范围。它应该看起来像这样:

<form action="index.php?action=upload" method="post" enctype="multipart/form-data">

关于php - 上传图像 php mysql 二进制文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9934723/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com