0

Now i am trying to upload pdf files by the form in php but when i upload it, it doesn't work because function is_uploaded_file($_FILES['file']['tmp_name']) return false

How can i solve it please ?? I am using localhost and I verify 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

This is my code :

Class

<?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

<!-- 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 -->
asked Nov 19, 2013 at 5:21
1
  • What is the size of the file you are uploading? Commented Nov 19, 2013 at 6:57

1 Answer 1

2

Maybe the file is to big or the destination directory is not writeable for php/apache.

Check the folder permission "E:/wamp/tmp" and try to upload a smaller file.

If a smaller file works, check these values in the php.ini file:

post_max_size
max_input_time
memory_limit
answered Nov 19, 2013 at 7:58
Sign up to request clarification or add additional context in comments.

1 Comment

thanks for the answer. i had only changed the upload_max_filesize = 50M entry in php.ini file. after setting post_max_size = 50M it works..

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.