Php Photo Upload

[Solved] Php Photo Upload | Perl - Code Explorer | yomemimo.com
Question : img upload in php

Answered by : kinjal-suryavanshi

 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. 

Source : | Last Update : Wed, 01 Sep 21

Question : upload images php mysql

Answered by : vivacious-vicua-i99ubttbp43p

$filename = $_FILES['image']['name'];
function uploadFiles($filename){ $ext = strtolower(pathinfo($filename, PATHINFO_EXTENSION)); $filetmp = $_FILES['avatar']['tmp_name'];	.......... .......... $target = $path.basename($filename); $upload = move_uploaded_file($filetmp,$target); if(!$upload){	$errors[] = 2; }
}

Source : | Last Update : Sun, 13 Feb 22

Question : php photo upload

Answered by : milan-niroula

 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. 

Source : https://www.codegrepper.com/search.php?q=php%20photo%20upload | Last Update : Wed, 01 Jun 22

Question : php helper function to upload image

Answered by : zealous-zebra-0tj9vs56u3l8

function uploadImage($image, $folderName, $defaultName = null)
{ // Check if the image is valid if (!$image->isValid()) { throw new \Exception('Invalid image.'); } $extension = $image->getClientOriginalExtension(); // Generate a unique filename for the image $filename = uniqid() . '_' . time() . '_' . $defaultName . '.' . $extension; if (!is_dir(public_path('uploads/' . $folderName))) { // create the directory if it does not exist mkdir(public_path('uploads/' . $folderName), 0777, true); } // Upload the image to the specified folder try { $image->move(public_path('uploads/' . $folderName), $filename); } catch (\Exception $e) { throw new \Exception('Error uploading image: ' . $e->getMessage()); } // Return the filename so it can be saved to a database or used in a view return $filename;
}

Source : | Last Update : Fri, 25 Aug 23

Question : Image_upload.php

Answered by : sazid-hasan-milon

<?php
// Include the database configuration file 
require_once 'dbConfig.php';
// If file upload form is submitted
$status = $statusMsg = '';
if(isset($_POST["submit"])){
    $status = 'error';
    if(!empty($_FILES["image"]["name"])) {
        // Get file info
        $fileName = basename($_FILES["image"]["name"]);
        $fileType = pathinfo($fileName, PATHINFO_EXTENSION);
        
        // Allow certain file formats
        $allowTypes = array('jpg','png','jpeg','gif');
        if(in_array($fileType, $allowTypes)){
            $image = $_FILES['image']['tmp_name'];
            $imgContent = addslashes(file_get_contents($image));
        
            // Insert image content into database
            $insert = $db->query("INSERT into images (image, created) VALUES ('$imgContent', NOW())");
            
            if($insert){
                $status = 'success';
                $statusMsg = "File uploaded successfully.";
            }else{
                $statusMsg = "File upload failed, please try again.";
            } 
        }else{
            $statusMsg = 'Sorry, only JPG, JPEG, PNG, & GIF files are allowed to upload.';
        }
    }else{
        $statusMsg = 'Please select an image file to upload.';
    }
}
// Display status message
echo $statusMsg;
?>

Source : https://www.codexworld.com/store-retrieve-image-from-database-mysql-php/ | Last Update : Tue, 19 Dec 23

Answers related to php photo upload

Code Explorer Popular Question For Perl