Ad block is installed and active. Please support us by disabling it.
HomeSaturday, January 20, 2018, 16:48:39
1

Upload Image with PHP [Example2]

Monday, February 9, 15, 01:07:57, 3 Yaers Ago Via wain, Hits: 3289
[Example2] Tutorial - How to upload and resize image with PHP
submit.php

Code:
<?php
if(isset($_POST['Submit']))
{
$current_image=$_FILES['image']['name'];
$extension = substr(strrchr($current_image, '.'), 1);
if (($extension!= "jpg") && ($extension != "jpeg")
&& ($extension != "gif")
&& ($extension != "png"))
{
die('Unknown extension');
}
$time = date("fYhis");
$new_image = $time . "." . $extension;
$destination="uploads/".$new_image;
$action = copy($_FILES['image']['tmp_name'], $destination);
if (!$action)
{
die('File copy failed');
}else{
echo "File copy successful";
}
}else{
?>
<form method="post" enctype="multipart/form-data" action="submit.php">
<input type="file" name="image" ><br>
<input type="submit" name="Submit" value="submit">
</form>
<?php
}
?>

KevinTheProGuy Sunday, April 24, 2011, 10:12:02

THANKS DUDE! HERE MY CODE!
THIS CODE WILL AUTOMATICLY CHANGE EVERY FILE TO .png

if(isset($_POST[\'Submit\']))
{
$current_image=$_FILES[\'image\'][\'name\'];
$extension = substr(strrchr($current_image, \'.\'), 1);

$str1 = str_replace(\"$extension\", \".png\", \"$extension\", $count);

$new_image = $myuser[username].$str1;
$destination=\"images/users/\".$new_image;
$action = copy($_FILES[\'image\'][\'tmp_name\'], $destination);
if (!$action)
{
echo \"Kon foto niet uploaden!\";
}else{
echo \"Foto is geupload.\";
}
}else{
?>






}
?>

vicko Sunday, February 12, 2012, 11:55:57

Thank you guys for the codes!

Sign In

Sponsor

Related

Syntax highlighting in Smarty

Syntax highlighting for Smarty - Google Code Prettify

Upload and Resize an Image with PHP

Tutorial - How to upload and resize image with PHP

PHP Tutorials

Useful step-by-step PHP tutorials for beginners

php Array

These functions allow you to interact with and manipulate arrays in various ways. Arrays are essential for storing, managing, and operating on sets of variables.

Link Generator PHP Script

This script will allow your visitors to create links online.To use the "link generator" script completely free , the "powered by" link at the bottom of the pages must stay intact.

PHP imagecreate

imagecreate() returns an image identifier representing a blank image of specified size.

Upload Attachment - PHP Tutorial

Upload attachment with PHP example, Requirement(s): PHP server

PHP str_replace

str_replace - This function returns a string or an array with all occurrences of search in subject replaced with the given replace value

MySQL Basic Functions

MySQL Basic Functions - select, delete, update..

Getimagesize

Getimagesize function will determine the size of any given image file and return the dimensions along with the file type and a height/width text string to be used inside a normal HTML IMG tag and the correspondant HTTP content type.
About Author

wain

Date Registered: Sun, Feb 8, 15
Last Time Online: Thu, Jun 15, 17
So far has created 115 entries.
wain
This author has not yet filled in any details.