Click here to Skip to main content
15,881,559 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
The
Move_uploaded_file()
funcition not working after upgrading to php 7.4. The upload works perfectly fine in 7.3 version. The error message I am getting is "
Quote:
PHP Warning: File upload error - unable to create a temporary file in Unknown on line 0
. It doesn't seems to be a permission issue since it works in 7.3 version. Please help me solve this issue. I have added my code below.

What I have tried:

   //print_r($_REQUEST);
 $name = $_FILES['file']['name'];
 $target_dir = "uploads/";
 $target_file = $target_dir . basename($_FILES['file']['name']);
// $makeId=$_REQUEST['makeId'];
 // Select file type
 $imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION));

 // Valid file extensions
 $extensions_arr = array("jpg","jpeg","png","gif");

 // Check extension
 if( in_array($imageFileType,$extensions_arr) ){
     echo "entered";
    // Upload file
    //move_uploaded_file($_FILES['file']['tmp_name'],$target_dir.$name);
    if(move_uploaded_file($_FILES['file']['tmp_name'],$target_dir.$name)){
       // Insert record
Posted
Updated 9-Dec-21 18:56pm
Comments
Chris Copeland 9-Dec-21 5:04am    
This might be an issue instead with PHP creating a temporary file on your file system when the file is uploaded. PHP would normally consume the upload and store it as a temporary file somewhere so it can be accessed (via the 'tmp_name' property). Have you tried checking the $_FILES['file']['error'] property to see if it contains more information?

$_FILES error messages
Vikas Uniqu 9-Dec-21 5:21am    
I am getting error number 6. "UPLOAD_ERR_NO_TMP_DIR" Value: 6; Missing a temporary folder.
Richard MacCutchan 9-Dec-21 5:04am    
The message is most likely telling you that one of the paths $_FILES['file']['tmp_name'] or $target_dir.$name is not valid.

According to your error your PHP configuration file may have been changed which has affected the temporary directory where files would be placed when they're uploaded. You can look at the following SO post for advice on how to fix this:

linux - I keep getting UPLOAD_ERR_NO_TMP_DIR while uploading file using PHP - Stack Overflow[^]

If you have your old PHP installation still available, consider cross-checking the configurations in the old php.ini file with the one in your new installation.
 
Share this answer
 
Comments
Vikas Uniqu 10-Dec-21 0:27am    
The php configuration file is correct. I have cross-checked. I noticed that echo sys_get_temp_dir(); gives the path "/tmp" but echo $_FILES["file"]['tmp_name']; gives empty.
Problem solved I added the full path for the temporary upload directory
upload_tmp_dir = "C:\inetpub\vhosts\tronsquared.com\tmp"
and it worked. Thank you for all who helped.
 
Share this answer
 
Comments
Chris Copeland 10-Dec-21 4:48am    
It might have been nice to accept my solution given that this is exactly what I told you to do, I don't see why this needed to be posted as a separate solution?
Vikas Uniqu 14-Dec-21 4:50am    
I just wanted to show what I did exactly that is all. You have helped me a lot by saving time.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900