hi i am working in php. and my assigned task is to upload a file and save it into the directory. i have install wamp into D-drive but it not working and dont get the path. i was trying the following:

<?php
  echo "Upload: " . $_FILES["file"]["name"] . "<br>";
  echo "Type: " . $_FILES["file"]["type"] . "<br>";
  echo "Size: " . ($_FILES["file"]["size"] / 1024) . " kB<br>";
  echo "Stored in: " . $_FILES["file"]["tmp_name"];
?>

its don't get the path of tem_name while if i install the wamp into C: it gets the folder and store the file into it. what the problem with this code? why it couldn't get the folder name??

Dani AI

Generated

Symptom recap: reports that $_FILES['file']['tmp_name'] is empty (var_dump shows an empty string) after installing WAMP on D:, while the same upload worked when WAMP was on C:. An empty tmp_name almost always means PHP failed to create the temporary upload file — not that the form value is missing. ’s suggestion to validate the $_FILES output and ’s pointer to upload_tmp_dir are on target, and ’s temp-dir idea is also useful.

Quick diagnostic (turn the numeric error code into readable text):

if (isset($_FILES['file'])) {
  $err = $_FILES['file']['error'];
  echo 'Upload error code: ' . $err . ' — ';
  switch ($err) {
    case UPLOAD_ERR_OK: echo 'OK'; break;
    case UPLOAD_ERR_INI_SIZE: echo 'Exceeds upload_max_filesize'; break;
    case UPLOAD_ERR_FORM_SIZE: echo 'Exceeds form MAX_FILE_SIZE'; break;
    case UPLOAD_ERR_PARTIAL: echo 'Partial upload'; break;
    case UPLOAD_ERR_NO_FILE: echo 'No file uploaded'; break;
    case UPLOAD_ERR_NO_TMP_DIR: echo 'Missing temporary folder'; break;
    case UPLOAD_ERR_CANT_WRITE: echo 'Failed to write to disk'; break;
    case UPLOAD_ERR_EXTENSION: echo 'Upload stopped by extension'; break;
    default: echo 'Unknown error'; break;
  }
}

Checklist of likely causes and fixes (apply in order):

  • Confirm the HTML form uses enctype="multipart/form-data" and the <input name="file"> matches the $_FILES key.
  • Check php.ini: file_uploads must be On; upload_max_filesize and post_max_size must be large enough; upload_tmp_dir should point to an existing directory. If upload_tmp_dir is empty, PHP uses the system temp folder.
  • Verify the directory configured for temporary uploads exists and is writable by the account running Apache (Windows services often run as LocalSystem or a service user — the service Log On account determines permissions).
  • If php.ini is edited, restart Apache/WAMP.
  • For confirmation, try creating a small file in the configured temp directory to test write permission; inspect Apache/PHP error logs for related messages.

If the upload error code is 6 (no tmp dir) or 7 (can't write), setting upload_tmp_dir to a writable folder on D: and ensuring the Apache service account has write permission will usually resolve it.

Recommended Answers

All 5 Replies

You mean that everything else is working (e.g. var_dump($_FILES["file"]["name"]) is correct) but the temporary file in the file system ( e.g. var_dump($_FILES["file"][" tmp_name"]) ) isn’t ?

If this is the case what outputs the last statement;

in the following link i have both html and php codes for which i was trying.

string '' (length=0) is the output when i use var_dump($_FILES["file"]["tmp_name"]) for the folder

Member Avatar for Member #120589

place

phpinfo();

into this file and search for upload_tmp_dir

have a look to see where it's pointing

$temp_file = sys_get_temp_dir();
echo $temp_file;
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.