【问题标题】:Upload file path no display上传文件路径不显示
【发布时间】:2015-08-20 13:09:00
【问题描述】:

我在我的 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 directive 设置为开启。

编辑-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";
...
...

编辑:我忘了提到when i dont use a path he upload it in database

【问题讨论】:

标签: php mysql forms file-upload


【解决方案1】:

能否检查一下文件是不是太大,超出了这两种配置的限制:

post_max_size
upload_max_filesize

您可以通过以下方式查看文件中的值:

<?php
phpinfo();
?>

编辑:

另一个建议是将 if 的主体括号放入,因为如果语句有效,则单行执行是不可信的。我认为问题可能是:

if (!file_exists($newname));

您插入数据库的方式也是从 $_REQUEST 中获取名称而不是新名称,您在哪里存储路径?

【讨论】:

  • 这与他们的代码不显示所有路径有什么关系?
  • "文件没有上传。"
  • 您错过了问题的全部要点;那........这就是为什么它没有被上传。再次检查他们的代码,非常非常仔细
  • 不大于 post_max_size upload_max_filesize
【解决方案2】:

我有一个“全局”表单,我将 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>

但是还是没有上传文件...

【讨论】:

    猜你喜欢
    • 2020-05-20
    • 1970-01-01
    • 1970-01-01
    • 2013-03-10
    • 2010-11-27
    • 1970-01-01
    • 1970-01-01
    • 2016-08-01
    • 1970-01-01
    相关资源
    最近更新 更多