现在我试图通过php中的表单上传pdf文件但是当我上传它时,它不起作用,因为函数is_uploaded_file($_FILES['file']['tmp_name'])
返回false
我该怎么解决呢? 我正在使用localhost,我验证了php.ini
; Whether to allow HTTP file uploads.
; http://php.net/file-uploads
file_uploads = On
; Temporary directory for HTTP uploaded files (will use system default if not
; specified).
; http://php.net/upload-tmp-dir
upload_tmp_dir = "E:/wamp/tmp"
; Maximum allowed size for uploaded files.
; http://php.net/upload-max-filesize
upload_max_filesize = 50M
这是我的代码:
班级
<?php
require '../includes/master.inc.php';
// Kick-out users who aren't logged in as an admin
$auth->requireAdmin('../login_admin_cp.php');
if (isset($_POST['btnsubmit'])) {
$error->blank($_POST['field_name'], "field_name");
if ($error->ok()) {
$field_name = $_POST['field_name'];
if (is_uploaded_file($_FILES['file']['tmp_name'])) {
// exit;
$mypath = "upload/";
$file_name = $_FILES['file']['name'];
$tmp = $_FILES['file']['tmp_name'];
$n = $mypath . $file_name;
$t = $_FILES['file']['size'];
$filesize = round($t / 1024) . " KB";
$extintion = strchr($n, ".");
$extintion = strtolower($extintion);
$file_extintion_allow = array(".pdf");
if ($n == "") {
echo "Error in upload";
} elseif (!in_array($extintion, $file_extintion_allow)) {
echo "من فضلك ادخل المادة بطريقة صحيحة";
exit;
} else {
//rename the file when upload by query name
$quaryname = rand(11111, 99999);
$rename = "../" . $mypath . $quaryname . $extintion;
$URL = substr($rename, 10, strlen($rename));
move_uploaded_file($tmp, $rename);
if (!empty($_POST['hide'])) {
$hide = $_POST['hide'];
$db->query("insert into field (field_name,url,hide)values('$field_name','$URL','$hide')");
$sess->set_flashdata('success_msg', 'تم حفظ المادة بنجاح');
redirect("field_new.php");
} else {
$db->query("insert into field (field_name,url,hide)values('$field_name','$URL','0')");
$sess->set_flashdata('success_msg', 'تم حفظ المادة بنجاح');
redirect("field_new.php");
}
}
} else {
exit;
}
} else {
$sess->set_flashdata('error_msg', 'حقل المادة فارغ');
}
}
// View
include('views/header.php');
include('views/field_form_new.php');
include('views/footer.php');
?>
表格
<!-- Form elements -->
<div class="grid_9">
<div class="module">
<h2><span> رفع المادة</span></h2>
<div class="module-body">
<?php echo $error;?>
<form action="field_new.php" method="post" name="myform" enctype="multipart/form-data">
<p>
<label> اسم المادة</label>
<input type="text" class="input-medium" name="field_name" value="" />
</p>
<p style="font-size:14px"> رفع المادة </p>
<p>
<label> الرابط</label>
<input type="text" class="input-medium" name="link" value="<?php $link; ?>" />
</p>
أو<br/> <br/>
<p>
<input type="hidden" class="input-medium" name="MAX_FILE_SIZE" value="1000000">
<label>رفع الملف </label>
<input type="file" class="input-medium" name="file" />
</p>
<p>
<input type="checkbox" name="hide" value="1" />تفعيل المادة
</p>
<fieldset>
<input class="submit-green" type="submit" name="btnsubmit" value="اضافة" />
</fieldset>
</form>
</div> <!-- End .module-body -->
</div> <!-- End .module -->
<div style="clear:both;"></div>
</div> <!-- End .grid_6 -->
答案 0 :(得分:2)
可能文件很大或目标目录不能写入php / apache。
检查文件夹权限"E:/wamp/tmp"
并尝试上传较小的文件。
如果较小的文件有效,请检查php.ini文件中的这些值:
post_max_size
max_input_time
memory_limit