简体   繁体   中英

error uploading file to server undefined index when uploading a photo to server

I have this php code and it cannot accept file uploads to the server, they tell me that undefined index file, how can i fix this error,

$target_path = public_path().'/uploads';
// dd($target_path);

$target_path = $target_path . basename( $_FILES['file']['name']);

if (move_uploaded_file($_FILES['file']['tmp_name'], $target_path)) {
    echo "Upload and move success";
} else {
echo $target_path;
    echo "There was an error uploading the file, please try again!";
}
?>

One or more these keys in your $_FILES array is undefined/not being passed from your form:

['file']
['file']['name']
['file']['tmp_name']

You should print out the value of $_FILES to determine which is undefined:

print_r($_FILES);

Then trace back the missing key(s) to your input form. Maybe theres a typo in the form.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM