Search
 
SCRIPT & CODE EXAMPLE
 

PHP

php file upload error

<?php   
// files specified
$file_name = $_FILES ['upload']['name'];
$file_size = $_FILES ['upload']['size'];
$file_tmp = $_FILES ['upload']['tmp_name'];

// the folder or default directory of uploaded files
$target_dir = "uploads/$file_name"; 

// Assigned variables to the http Post method
$submit = $_POST['submit'];

// ASSIGN variables to the FILES super variable;
$files = $_FILES['upload']['name'];

// Assigned variables to the supported files type 
$file_types = array('png','ptt','php','mp4','jpg','jpeg','txt','zip','pdf');

// specify where the supported extensions will start from
$file_ext = explode('.', $file_name);
$file_ext = strtolower(end($file_ext));

// Upload script starts here

if (isset($submit)) {
    if (!empty($files)) {
        if (in_array($file_ext,$file_types)) {
            if ($file_size <= 1200000) {
              // 1200000 = 1.2mb
                move_uploaded_file($file_tmp,$target_dir);
                echo '<p style="color: green">Upload Successful !</p>';
            } else {
                echo '<p style="color: red">File size too large !</p>';
            }
        }else {
            echo '<p style="color: red"> Invalid file format!</p>';
        }
    }else {
        echo '<p style="color: red">file not selected!!</p>';
    }
}
Comment

PREVIOUS NEXT
Code Example
Php :: Flutter migrate to Android Studio mac os 
Php :: load database in codeigniter 
Php :: object php 
Php :: laravel set config value dynamically 
Php :: symfony redirect to previous page 
Php :: php array to string 
Php :: how assign default value to laravel migration column 
Php :: php convert object to array nested 
Php :: dummy data in laravel 
Php :: php isset post 
Php :: php unix timestamp to date 
Php :: get array key based on value php 
Php :: php random number generator 
Php :: get value by today yesterday in laravel 
Php :: laravel query latest 
Php :: run shell script from php file 
Php :: get month first date and last date in php 
Php :: from user id to user role wordpress 
Php :: php foreach random 
Php :: how to prompt user for input in php 
Php :: php datetime sub minutes 
Php :: how add new column in larevel with migration 
Php :: how to retrieve data from database using select option in laravel 
Php :: laravel collection keys 
Php :: laravel 5.8 cors 
Php :: yii2 html a 
Php :: Fatal error: Allowed memory size of 1610612736 bytes exhausted but already allocated 1.75G 
Php :: ent_quotes in php 
Php :: base64 enocode php 
Php :: route closure function in laravel 
ADD CONTENT
Topic
Content
Source link
Name
8+2 =