Search
 
SCRIPT & CODE EXAMPLE
 

PHP

Upload file in php

<?php
// connect to the database
$conn = mysqli_connect('localhost', 'root', '', 'file-management');

// Uploads files
if (isset($_POST['save'])) { // if save button on the form is clicked
    // name of the uploaded file
    $filename = $_FILES['myfile']['name'];

    // destination of the file on the server
    $destination = 'uploads/' . $filename;

    // get the file extension
    $extension = pathinfo($filename, PATHINFO_EXTENSION);

    // the physical file on a temporary uploads directory on the server
    $file = $_FILES['myfile']['tmp_name'];
    $size = $_FILES['myfile']['size'];

    if (!in_array($extension, ['zip', 'pdf', 'docx'])) {
        echo "You file extension must be .zip, .pdf or .docx";
    } elseif ($_FILES['myfile']['size'] > 1000000) { // file shouldn't be larger than 1Megabyte
        echo "File too large!";
    } else {
        // move the uploaded (temporary) file to the specified destination
        if (move_uploaded_file($file, $destination)) {
            $sql = "INSERT INTO files (name, size, downloads) VALUES ('$filename', $size, 0)";
            if (mysqli_query($conn, $sql)) {
                echo "File uploaded successfully";
            }
        } else {
            echo "Failed to upload file.";
        }
    }
}
Comment

php upload file

<?php
$filename = basename($_FILES['myfile']['name']);
if (move_uploaded_file($_FILES['myfile']['tmp_name'], "files/$filename")) {
  echo "File uploaded";
} else {
  echo "An error occurred";
}
?>
<form action="<?php echo htmlspecialchars($_SERVER['REQUEST_URI']); ?>" method="post" enctype="multipart/form-data">
  <label>File: <input type="file" name="myfile" /></label>
    <input type="submit" value="send" />
  </form>
Comment

img upload in php


                if(isset($_FILES['image']))
                {
                    $img_name = $_FILES['image']['name'];      //getting user uploaded name
                    $img_type = $_FILES['image']['type'];       //getting user uploaded img type
                    $tmp_name = $_FILES['image']['tmp_name'];   //this temporary name is used to save/move file in our folder.
                    
                    // let's explode image and get the last name(extension) like jpg, png
                    $img_explode = explode(".",$img_name);
                    $img_ext = end($img_explode);   //here we get the extension of an user uploaded img file

                    $extension= ['png','jpeg','jpg','gif']; //these are some valid img extension and we are store them in array.
                
Comment

Image upload in PHP code with databases

$file = file(1000,100000)."-".$_FILES['file']['name'];
    $file_loc = $_FILES['file']['tmp_name'];
 $file_size = $_FILES['file']['size'];
 $file_type = $_FILES['file']['type'];
 $folder="uploads/";
Comment

php photo upload

  if(isset($_FILES['image']))
                {
                    $img_name = $_FILES['image']['name'];      //getting user uploaded name
                    $img_type = $_FILES['image']['type'];       //getting user uploaded img type
                    $tmp_name = $_FILES['image']['tmp_name'];   //this temporary name is used to save/move file in our folder.
                    
                    // let's explode image and get the last name(extension) like jpg, png
                    $img_explode = explode(".",$img_name);
                    $img_ext = end($img_explode);   //here we get the extension of an user uploaded img file

                    $extension= ['png','jpeg','jpg','gif']; //these are some valid img extension and we are store them in array.
                
Comment

PREVIOUS NEXT
Code Example
Php :: php replace br 
Php :: qr code generator php 
Php :: php timeout 
Php :: how to upload two files on same form different path in codeigniter 
Php :: php super 
Php :: laravel model wherein update 
Php :: office 2013 
Php :: stripslashes 
Php :: php find if string contains words from list index 
Php :: h:i:s explode in php by ":" 
Php :: random string value laravel 
Php :: Laravel - Query Builder Left join 
Php :: how to get meta information from pagination in laravel controller 
Php :: laravel collection namespace 
Php :: get joomla group ids 
Php :: codeigniter 3 where not in 
Php :: php validate colour 
Php :: print in file php 
Php :: minishlink/web-push v5.2.5 requires ext-gmp * 
Php :: php substr 
Php :: add object in array php 
Php :: laravel fontawesome 
Php :: calculate array length in php 
Php :: artisan laravel require bootstrap 
Php :: php isset form submit 
Php :: twig log variable 
Php :: laravel use controller function in another controller 
Php :: explode return empty array 
Php :: php xml to json 
Php :: alias to change php version on ubuntu 
ADD CONTENT
Topic
Content
Source link
Name
2+8 =