我在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
设置为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";
...
...
编辑:我忘了提及when i dont use a path he upload it in database
。
答案 0 :(得分:0)
您可以检查文件是否过大并超出这两种配置的限制:
post_max_size
upload_max_filesize
您可以使用以下命令查看文件中的值:
<?php
phpinfo();
?>
编辑:
另一个建议是放置if的主体括号,因为如果该语句有效则单行执行,不能被信任。我认为问题可能是:
if (!file_exists($newname));
另外,您插入数据库的方式是从$ _REQUEST而不是新名称中取名,并在何处存储路径?
答案 1 :(得分:0)
我有一个&#34;全球&#34;表格和我推出的enctype =&#34; multipart / form-data&#34;在它中,它可以保存表中的路径。
之前在下面的表格中并且不认识它。
Exception in thread "main" java.lang.IllegalStateException: HashCode violation: the hashCode of tabu (Vehicle>10) probably changed since it was inserted in the tabu Map or Set.
at org.optaplanner.core.impl.localsearch.decider.acceptor.tabu.AbstractTabuAcceptor.adjustTabuList(AbstractTabuAcceptor.java:108)
at org.optaplanner.core.impl.localsearch.decider.acceptor.tabu.AbstractTabuAcceptor.stepEnded(AbstractTabuAcceptor.java:98)
at org.optaplanner.core.impl.localsearch.decider.LocalSearchDecider.stepEnded(LocalSearchDecider.java:159)
at org.optaplanner.core.impl.localsearch.DefaultLocalSearchSolverPhase.stepEnded(DefaultLocalSearchSolverPhase.java:127)
at org.optaplanner.core.impl.localsearch.DefaultLocalSearchSolverPhase.solve(DefaultLocalSearchSolverPhase.java:83)
at org.optaplanner.core.impl.solver.DefaultSolver.runSolverPhases(DefaultSolver.java:190)
at org.optaplanner.core.impl.solver.DefaultSolver.solve(DefaultSolver.java:155)
at org.optaplanner.examples.cloudbalancing.app.CloudBalancingHelloWorld.main(CloudBalancingHelloWorld.java:56)
但仍然没有上传文件...