0
//=============== PDF File Upload=====================
if (isset($_FILES["pdfile"])) {
 $filename = $_FILES['pdfile']['name'];
 $dir = "../pdfs/students/".$filename;
 $tmp_name = $_FILES['pdfile']['tmp_name'];
 $file1 = explode('.',$filename);
 $ext = $file1[1];
 $allow = array('pdf');
 if(in_array($ext, $allow))
 move_uploaded_file($filename, $dir);
 }
 else
 die("There is no file to upload.");
//=============== End Pdf File Upload=====================
//=============== Image File Upload=====================
if(isset($_FILES['profile']['tmp_name'])){
 $dir = "../images/students/".$id.".jpg";
 $file = $_FILES['profile']['tmp_name'];
 if(move_uploaded_file($file, $dir)){
 echo "Image Uploaded Successfully";
 $pic = mysqli_query($con, "update students set profile ='$id.jpg' where id = $id ")or die(mysqli_error($con));
 }
 else{
 echo "Error Occured";
 }
 }
//=============== End Image File Upload=====================

PDF File didn't get upload in directory. I don't know why and same code for profile picture uploading works fine. Help me with this guys.

neubert
17k28 gold badges140 silver badges264 bronze badges
asked May 14, 2022 at 20:48
3
  • What is the output of the script? What text are you seeing? Commented May 14, 2022 at 20:50
  • output of the script says pdf file uploaded successfully but when i checked in that directory there is no file showed up. Commented May 14, 2022 at 21:05
  • stackoverflow.com/a/72243993/6127393 Commented May 14, 2022 at 21:41

3 Answers 3

0

Sorry I didn't see at first time at my code. the error is of $tmp_name at move_upload_file($filename, $dir). Replace $filename to $tmp_name and it works fine.

//=============== PDF File Upload=====================
if (isset($_FILES["pdfile"])) {
 $filename = $_FILES['pdfile']['name'];
 $dir = "../pdfs/students/".$filename;
 $tmp_name = $_FILES['pdfile']['tmp_name'];
 $file1 = explode('.',$filename);
 $ext = $file1[1];
 $allow = array('pdf');
 if(in_array($ext, $allow))
 move_uploaded_file($filename, $dir);
 }
 else
 die("There is no file to upload.");
//=============== End Pdf File Upload=====================
answered May 14, 2022 at 21:29
Sign up to request clarification or add additional context in comments.

Comments

0

Change this line

move_uploaded_file($filename, $dir);

To this

move_uploaded_file($tmp_name, $dir);
answered May 14, 2022 at 21:30

Comments

0
if (isset($_FILES["pdfile"])) {
 $filename = $_FILES['pdfile']['name'];
 $dir = "../pdfs/students/".$filename;
 $tmp_name = $_FILES['pdfile']['tmp_name'];
 $file1 = explode('.',$filename);
 $ext = $file1[1];
 $allow = array('pdf');
 if(in_array($ext, $allow))
 move_uploaded_file($filename, $dir);
}

move_uploaded_file should be:

move_uploaded_file($tmp_name, $dir);

more tips:

<?php
if (isset($_FILES["pdfile"])) {
 $filename = $_FILES['pdfile']['name'];
 $tmp_name = $_FILES['pdfile']['tmp_name'];
 $dir = "../pdfs/students/" . $filename;
 $file1 = explode('.',$filename);
 // use end() to get last
 // for example: filename.jpg.pdf
 $ext = end($file1);
 $allow = array('pdf');
 if(in_array($ext, $allow))
 move_uploaded_file($tmp_name, $dir);
}
answered May 14, 2022 at 21:26

2 Comments

ThankYou, I just saw this error couple of mins ago.
np .. u can see the tips for ext.

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.