gpt4 book ai didi

php - 上传文件路径不显示

转载 作者:行者123 更新时间:2023-11-29 22:21:27 25 4
gpt4 key购买 nike

我在 sql 数据库中上传路径时遇到问题。不显示所有路径。

这是 php 代码:

$rd2 = mt_rand(1000, 9999) . "_File";
if ((!empty($_FILES["uploaded_file"])) && ($_FILES['uploaded_file']['error'] == 0))
$filename = basename($_FILES['uploaded_file']['name']);

$ext = substr($filename, strrpos($filename, '.') + 1);
if (($ext != "exe") && ($_FILES["uploaded_file"]["type"] != "application/x-msdownload"));
$newname = "uploads/" . $rd2 . "_" . $filename;

if (!file_exists($newname));

if ((move_uploaded_file($_FILES['uploaded_file']['tmp_name'], $newname)));
$query = "insert into files (file_id,floc,subid,fname,fdesc,tcid)
values ($newstd,'$newname',
'".htmlspecialchars($_REQUEST['subid'], ENT_QUOTES)."',
'".htmlspecialchars($_REQUEST['fname'], ENT_QUOTES)."',
'".htmlspecialchars($_REQUEST['fdesc'], ENT_QUOTES)."',
'".$_SESSION['tcid']."')";

if (!@executeQuery($query)) {
if (mysql_errno () == 1062) //duplicate value
$_GLOBALS['message'] = "Given Subject Name voilates some constraints,
please try with some other name.";
else
$_GLOBALS['message'] = mysql_error ();
}
else
$_GLOBALS['message'] = "Successfully New Subject is Created.";
}

closedb();

代码正在运行,并在数据库中显示如下:http://i.stack.imgur.com/Z5jmb.png

它应该显示uploads/2654_File_filename.docx

并且文件未上传。

表格位于表格中:

<tr>
<td> File</td>
<td>
<form action="cursuri.php" method="post" enctype="multipart/form-data">
<input type="file" name="uploaded_file" id="uploaded_file"></form>
</td>
</tr>

我用过这个:http://www.w3schools.com/php/php_file_upload.asp但同样不起作用

我使用的是 xampp 5.6.8 和 php.ini,并且 file_uploads 指令 设置为 On。

编辑 - newstd 是:

$result = executeQuery("select max(file_id) as fid from files");
$r = mysql_fetch_array($result);
if (is_null($r['fid']))
$newstd = 1;
else
$newstd=$r['fid'] + 1;


$result = executeQuery("select fname as fid from files where
fname='" . htmlspecialchars($_REQUEST['fname'], ENT_QUOTES) . "'
and tcid=" . $_SESSION['tcid'] . ";");

// $_GLOBALS['message']=$newstd;
if (empty($_REQUEST['fname']) || empty($_REQUEST['fdesc'])) {
$_GLOBALS['message'] = "Some of the required Fields are Empty";
} else if (mysql_num_rows($result) > 0) {
$_GLOBALS['message'] = "Sorry Subject Already Exists.";
} else {

}
$rd2 = mt_rand(1000, 9999) . "_File";
...
...

编辑:我忘了提及当我不使用路径时,他会将其上传到数据库

最佳答案

我有一个“全局”表单,我在其中放入了 enctype="multipart/form-data",它可以将路径保存在表中。

之前是下面的表格,但无法识别它。

<tr>
<td> File</td>
<td>
<form action="cursuri.php" method="post" enctype="multipart/form-data">
<input type="file" name="uploaded_file" id="uploaded_file"></form>
</td>

但仍然没有上传文件...

关于php - 上传文件路径不显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30668967/

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