简体   繁体   中英

Uploaded file is not saved in folder

I have created one form in which one file field is there where the file is uploaded and saved in a folder named "att". code is as:

if($_FILES['file'] != '') 
 {
    //Settings 

    $allowed_extensions = array("jpg", "jpeg", "gif", "bmp", "pdf", "docx","xlsx");
    echo $upload_folder = './att/'; //<-- this folder must be writeable by the script


    $errors ='';

    //Get the uploaded file information
    echo $name_of_uploaded_file = basename($_FILES['file']['name']);

    //get the file extension of the file
    $type_of_uploaded_file = substr($name_of_uploaded_file, 
                            strrpos($name_of_uploaded_file, '.') + 1);

    $size_of_uploaded_file = $_FILES["file"]["size"];

This code is run but the file is not show in folder. What is the problem in code

Please add move_uploaded_file() on the code.

Something like these:

<?php
if($_FILES['file'] != '') 
 {
    //Settings 

    $allowed_extensions = array("jpg", "jpeg", "gif", "bmp", "pdf", "docx","xlsx");
    $upload_folder = './att/'; //<-- this folder must be writeable by the script


    $errors ='';

    //Get the uploaded file information
    $name_of_uploaded_file = basename($_FILES['file']['name']);

    //get the file extension of the file
    $type_of_uploaded_file = substr($name_of_uploaded_file, 
                            strrpos($name_of_uploaded_file, '.') + 1);

     $size_of_uploaded_file = $_FILES["file"]["size"];

     move_uploaded_file($name_of_uploaded_file, $upload_folder);     
  }

?>

Make sure the folder att is rewritable.

You are just using file details not moving it. For moving you sholud use move_uploaded_file \\

eg: 

move_uploaded_file($_FILES['file']['tmp_name'], "PLACE WHERE YOU WANT TO MOVE")

You have to use move_uploaded_file function. Refer to this example: move_uploaded_file

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