Javascript 使用PHP上传PDF时出现的问题
我的PDF上传脚本有2个问题Javascript 使用PHP上传PDF时出现的问题,javascript,php,html,pdf,Javascript,Php,Html,Pdf,我的PDF上传脚本有2个问题 我注意到只有某些PDF文件会上传,而某些PDF文件不会。我已经注意到,那些工作的速度不到100 kbs。没有的在MB中。有没有办法改变这一点 如果上载的PDF文件名称中有空格,则会导致链接断开。有没有一种方法可以对它进行编码,这样html就能正确地引导它?试图通过谷歌搜索,但什么也找不到。希望你们能对此有所了解 以下是我的PHP: <?php include_once 'includes/db_connect.php'; include_once 'inclu
<?php
include_once 'includes/db_connect.php';
include_once 'includes/psl-config.php';
$title = $_POST['title'];
$id = $_POST['id'];
if ($_FILES["file"]["size"] > 0)
{
$targetfolder = "uploads/";
$targetfolder = $targetfolder . basename( $_FILES['file']['name']) ;
$fileName = basename( $_FILES['file']['name']) ;
$url = $_POST['url'];
$file_type=$_FILES['file']['type'];
echo "hiii";
if ($file_type=="application/pdf" || $file_type=="application/x-pdf")
{
unlink($url);
if(move_uploaded_file($_FILES['file']['tmp_name'], $targetfolder))
{
if ($insert_stmt = $mysqli->prepare("UPDATE content SET title = ?, fileName = ?, url = ? WHERE id = ?;"))
{
$insert_stmt->bind_param('sssd', $title, $fileName, $targetfolder, $id );
if (! $insert_stmt->execute())
{
echo "Error processing your request";
}
echo "<p>The file is updated</p>";
echo"<p>Return to the <a href='protected_page.php'>content page</a></p>";
}
else
{
echo "<p> Failed to upload to the server</p>
<p> Return back to <a href='edit_content.php'>edit page</a></p>";
}
}
else
{
echo "<p>Problem uploading file</p>";
}
}
else
{
echo "<p>You may only upload PDFs</p>
<p> Return back to <a href='edit_content.php'>edit page</a></p>
";
}
}
else
{
if ($insert_stmt = $mysqli->prepare("UPDATE content SET title = ? WHERE id = ?;"))
{
$insert_stmt->bind_param('sd', $title, $id );
if (! $insert_stmt->execute())
{
header('Location: ../error.php?err=Registration failure: update');
}
echo "<p>The file was updated</p>";
echo"<p>Return to the <a href='protected_page.php'>content page</a></p>";
}
else
{
echo "<p> Failed to upload to the server</p>
<p> Return back to <a href='add_content.php'>edit page</a></p>";
}
}
?>
对于问题#2,您可以重命名上载的文件,用下划线替换空格,这样您就不会得到断开的链接
$targetfolder = $targetfolder . basename( $_FILES['file']['name']);
将是
$targetfolder = $targetfolder . basename( str_replace(' ', '_', $_FILES['file']['name']) );
对于上载大小的问题。。。问题1已修复。只是附带说明一下,它要求我重新启动apache,以使更改对php.ini文件产生影响。我找到了另一种解决方法。我刚用了“rawurlencode”
$targetfolder = $targetfolder . basename( str_replace(' ', '_', $_FILES['file']['name']) );