php download code example

Example 1: install php windows 10

1. Download Thread safe 32/64 bit zip package PHP8 from 
   https://windows.php.net/download#php-8.0
2. Extract the zip package and paste the extracted folder onto your 
    desired drive( Drive C:\ for example)
3. Rename the folder to php8( or any name that you like)
4. One this folder and look for php.ini-development file
5. Make a copy of this file and rename copy version to php.ini
6. Open php.ini file with your preferred text editor and uncomment PHPIniDir “ext”
7. Save the file and close the editor.

## Set PHP 8 to System's Path
1. Open php8 folder and copy and folder path
2. Press Windows Key on your keyboard and type 'variable' and hit Enter
3. Click Environment Variables
4. Click Edit and Click NEW on the right
5. Paste the php8 folder path
6. Click OK, OK, OK

## Installing composer
Run the following commands
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('sha384', 'composer-setup.php') === '795f976fe0ebd8b75f26a6dd68f78fd3453ce79f32ecb33e7fd087d39bfeb978342fb73ac986cd4f54edd0dc902601dc') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"

QUICK QUESTION: Have you heard of Windows SubSystem for Linux (wsl)? 
Check it out

Example 2: php upload

// To change: FILENAME, array with allowed extensions, Max Filesite, Filepath
if(upload("FILENAME", array("jpeg","jpg","png"), 209715, "C:/xampp/htdocs/")){
        echo "Success";
    }


function upload($f_name, $f_ext_allowed, $f_maxsize, $f_path){

      $f_name_2 = $_FILES[$f_name]['name'];
      $f_size  =  $_FILES[$f_name]['size'];
      $f_tmp   =  $_FILES[$f_name]['tmp_name'];
      $f_error =  $_FILES[$f_name]['error'];
      $f_ext   = strtolower(end(explode('.',$f_name_2)));
      $f_rename = $_SESSION['uid'] . "." . $f_ext;

        if($f_error == 0 && in_array($f_ext, $f_ext_allowed) 
        && $f_size < $f_maxsize && mb_strlen($f_name_2, "UTF-8") < 225 
        && preg_match("`^[-0-9A-Z_\.]+$`i", $f_name_2)){
            if(move_uploaded_file($f_tmp, $f_path . $f_name_2){
                return true;
            }else{
                return false;
            }
        }else{
            return false;
        }
}

Example 3: php 5 windows

pub   2048D/5DA04B5D 2012-03-19
      Key fingerprint = F382 5282 6ACD 957E F380  D39F 2F79 56BC 5DA0 4B5D
uid                  Stanislav Malyshev (PHP key) <[email protected]>
uid                  Stanislav Malyshev (PHP key) <[email protected]>
uid                  Stanislav Malyshev (PHP key) <[email protected]>

Example 4: php download script

<?php
/*Actual filename = 'attachment.zip' (Unknown to the viewers).
When downloaded to be saved as 'mydownload.zip'.
*/
$filename='mydownload.zip';
@header("Content-type: application/zip");
@header("Content-Disposition: attachment; filename=$filename");
echo file_get_contents('attachment.zip');
?>