gpt4 book ai didi

php 表单在线发送空数据,但在本地主机上工作正常

转载 作者:行者123 更新时间:2023-11-29 23:56:29 26 4
gpt4 key购买 nike

我在 php 中得到了一些表单,这样我就可以将数据上传到 mysql 数据库中,我已经使用 xampp 在本地服务器上进行了试验,但是当我将文件上传到我的主机 ftp 时,表单不起作用,所以,我是认为这与我将此文件和“connect.php”也置于密码限制下这一事实有关,这也与文件权限有关,但我已经向数据库用户授予了权限,并且文件的权限,我也尝试过没有密码保护的东西,但什么都没有,总是有相同的结果,所以我开始进行一些实验,我发现图像可以很好地上传到数据库中,但没有其他方法可以做到这一点,知道我尝试“回显”其他输入结果,但没有显示任何内容,我得出的结论是我的表单正在发送空数据,有人可以告诉我我是否正确?为什么会发生这种情况!请帮忙,这是我的代码...

<html>
<head>
<meta charset="UTF-8">
<title>Untitled Document</title>
</head>
<body>
<div id="slider_upload">

<h1>Slider principal</h1>
<div class="forma">

<form action="sliderPrincipal.php" method="post" enctype="multipart/form-data">
<p><label for="encabezado">Encabezado</label>
<input type="text" id="encabezado" name="encabezado" /></p><br>
<input type="hidden" name="MAX_FILE_SIZE" value="1048576" />
<p><label for="fileupload">File to upload</label>
<input type="file" id="fileupload" name="fileupload" /></p><br>
<p><label for="articulo">Articulo</label>
<textarea id="articulo" name="articulo" rows="26" style="width: 100%;" >Escribir aqui</textarea></p><br>
<button type="submit" name="submit" value"send">Upload File</button>
</form><br><br>

</div>
</div>

<div class="message">
<?php



$file_dir = "../uploaded";

if (isset($_POST['encabezado'])){
$encabezado = mysql_real_escape_string($_POST['encabezado']);
$articulo = mysql_real_escape_string($_POST['articulo']);
}


foreach($_FILES as $file_name => $file_array){
//echo "path: ".$file_array['tmp_name']."<br />\n";
//echo "name: ".$file_array['name']."<br/>\n";
//echo "type: ".$file_array['type']."<br/>\n";
//echo "size: ".$file_array['size']."<br/><br/>\n";
//echo "encabezado ".$encabezado;

if(is_uploaded_file($file_array['tmp_name'])){
move_uploaded_file($file_array['tmp_name'], "$file_dir/".$file_array['name']) or die ("Your image couldnt be uploaded <br>");
$newpath = addslashes("uploaded/".$file_array['name']);
include "connect.php";
$addfile = "INSERT INTO slider (encabezado, image, articulo) VALUES ('$encabezado','$newpath', '$articulo')";
$result = mysql_query($addfile);
if ( $result === FALSE ) {
echo "your post could not be uploaded but we already got your image in our files ";
} else{
echo '<p style="padding: 20px;"><h1>Your post was successfully uploaded <h2></p><br><br>';

}


mysql_close();

} else "No file found";


}

?>
</div>
</div>
</body>
</html>

最佳答案

$file_dir = "../uploaded";
if($_REQUEST['submit']) {
$encabezado = mysql_real_escape_string($_POST['encabezado']);
$articulo = mysql_real_escape_string($_POST['articulo']);
foreach($_FILES as $file_name => $file_array){
if(is_uploaded_file($file_array['tmp_name'])){
move_uploaded_file($file_array['tmp_name'], "$file_dir/".$file_array['name']) or die ("Your image couldnt be uploaded <br>");
$newpath = addslashes("uploaded/".$file_array['name']);
include "connect.php";
$addfile = "INSERT INTO slider (`encabezado`, `image`, `articulo`) VALUES ('$encabezado','$newpath', '$articulo')";
$result = mysql_query($addfile);
if ( $result === FALSE ) {
echo "your post could not be uploaded but we already got your image in our files ";
} else{
echo '<p style="padding: 20px;"><h1>Your post was successfully uploaded <h2></p><br><br>';

}
mysql_close();

} else "No file found";


}
}

尝试上面的代码。

注意:未经测试。

关于php 表单在线发送空数据,但在本地主机上工作正常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25300451/

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