Okay
  Public Ticket #3016472
doing an actual upload
Closed

Comments

  • Andrew Cole started the conversation

    The template we purchased allows me to drag and drop images but stops there. I need to know what code adaptations to make to cause the image to actually upload onto my server

  • [deleted] replied

    Hi Andrew Cole,

    By default file uploading is not handled by Neon theme, it is a "fake" upload success message for security reasons.

    To process and move uploaded file from:

    https://demo.neontheme.com/forms/file-upload/

    Example: Dropzone - Drag n' Drop File Upload

    It sends requests to "data/upload-file.php"

    In upload-file.php to handle upload you can add the following example code (but you should add security measures as well):

    $ds = DIRECTORY_SEPARATOR;  //1
    $storeFolder = 'uploads';   //2
    if ( ! empty( $_FILES ) ) {
        $tempFile = $_FILES['file']['tmp_name'];          //3
        $targetPath = dirname( __FILE__ ) . $ds . $storeFolder . $ds;  //4
        $targetFile = $targetPath . $_FILES['file']['name'];  //5
        move_uploaded_file( $tempFile, $targetFile ); //6
    }

     

    1. Store directory separator (DIRECTORY_SEPARATOR) to a simple variable. This is just a personal preference as we hate to type long variable name.
    2. Declare a variable for destination folder.
    3. If file is sent to the page, store the file object to a temporary variable.
    4. Create the absolute path of the destination folder.
    5. Create the absolute path of the uploaded file destination.
    6. Move uploaded file to destination.

    Here is the article that explains the full process:

    https://startutorial.com/view/dropzonejs-php-how-to-build-a-file-upload-form

    I hope this helps you.