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

Upload Image With PHP

Monday, February 9, 15, 01:12:13, 3 Yaers Ago Via wain, Hits: 3745
[Example3] Tutorial - How to upload image in php.
upload.php

Code:
<?php
if(isset($_POST['Submit']))
{
$current_image=$_FILES['image']['name'];
$extension = substr(strrchr($current_image, '.'), 1);
if (($extension!= "jpg") && ($extension != "jpeg"))
{
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="upload.php">
<input type="file" name="image" ><br>
<input type="submit" name="Submit" value="submit">
</form>
<?php
}
?>

tastro.org Friday, June 4, 2010, 13:06:14

simple and but like it should be! great article m8. ;)

fada Saturday, June 26, 2010, 09:06:17

good work done here keep it up

Prabhu Sunday, September 12, 2010, 10:29:13

Ya ..
It is Very nice and Simple
Thank U very much
.............

NIL KHAIR Friday, October 15, 2010, 06:57:25

Thnks sir for giving me this code thnk u so muchhhhhhhh

Sreejith.K.S Monday, November 8, 2010, 02:02:29

Nice n Simple,Thnx..

john Monday, November 22, 2010, 21:59:46

Can you pls post what is needed to limit image size?

btw very simple great!

Thanks in advance

Gochu Tuesday, December 14, 2010, 07:17:11

Thanks a lot.. Is easy for beginners also..

Vivek Tuesday, December 14, 2010, 07:20:10

Thanks a lot.. Very simple and appropriate..

custom php mysql programming Thursday, December 23, 2010, 06:01:27

I got very clear idea for my image upload...
keep on update new post...
Thank you!!

Hammad Wednesday, February 16, 2011, 12:14:37

Thanx its very helpful and easy

Sudhir Sharma Friday, March 11, 2011, 06:44:36

This is Nice idea but i think it may be more easy to fetch image from data base after upload image if we concatenate the userid with image name instead time of uploading image which making it unique in uploads folder.

kiki Friday, March 25, 2011, 10:40:27

nice piece of code

Hanif Sunday, March 27, 2011, 17:09:35

Great dear.... its so easy to implement... thanks a lot.

ROCKESH RONITH Thursday, April 7, 2011, 03:55:01

Thanks...its too good and easy to understand..easy to implement.....
tahnxxx a lot....

Raghu Friday, April 8, 2011, 04:31:56

its very nice
Thank U

viktorija Saturday, April 30, 2011, 18:24:29

Very useful tutorial, thank you

jolanda Friday, May 20, 2011, 07:14:22

Very nice tutorial. Thx.

benkbauer Thursday, June 2, 2011, 11:18:19

i can\'t browser the image..
can someone help me?

prakash Tuesday, October 18, 2011, 13:10:52

very nice thanQ

Sus Wednesday, November 2, 2011, 10:29:58

it is simple

jagesh maharjan Saturday, November 5, 2011, 06:50:45

now after upload, how do i display that image in the web page.

roshan Sunday, November 6, 2011, 04:14:02

i want to know where the image was uploaded.

Robert Monday, November 21, 2011, 05:28:56

Thank you very much... simple + easy plug-in
=D

Robert Monday, November 21, 2011, 05:30:23

echo \"Thank you very much...
It is simple and understandable...\";

Minhaj Wednesday, January 18, 2012, 02:22:57

Thankssssssssssssssssssss

Hims Thursday, January 19, 2012, 06:52:52

nice tutorial!!thnx

bistro Sunday, February 12, 2012, 12:01:46

This is great, thanks you for the code.

newly Friday, February 17, 2012, 14:44:55

simple.....

Goku Monday, February 27, 2012, 06:02:33

This is really useful! ..Thanks for sharing.

MANU Friday, March 30, 2012, 09:26:20

Very nice !!

ajay Saturday, March 31, 2012, 07:21:57

very very thankzzz

nathan Wednesday, April 4, 2012, 13:06:11

How to Store in database please tell me

micky Wednesday, April 4, 2012, 19:54:01

@nathan
.....
echo \"File copy successful\";
$result = mysql_query(\"INSERT INTO mydatabase (image)
VALUES (\'$new_image\')\") or
die(mysql_error());

Minakshi Thursday, April 12, 2012, 10:38:10

Thanks.it works

minakshi Thursday, April 12, 2012, 10:45:45

thanks ,
but how to retrive from database

wain Thursday, December 8, 2016, 05:43:42

Read also How to check if uploaded file is image in php http://devcodepro.com/view/13/1/How-to-check-if-uploaded-file-is-image-in-php

Sign In

Sponsor

Related

Create dynamic Web Pages with PHP & MySQL

Create dynamic Web Pages with PHP & MySQL, Requirement(s): PHP Server, MySQL

Show / Hide Div with CSS

CSS Display and Visibility:The visibility property specifies whether or not an element is visible.

Captcha V1 - Free PHP Script

An anti-spam form protection image written in PHP, Version: 1.1.

PHP $_GET Function

Get function in PHP

PHP Date Examples

Returns a string formatted according to the given format string using the given integer timestamp or the current time if no timestamp is given.

Advanced Contact Form - PHP Script

Advanced Contact Form with email and form field validation. Features: HTML Output(Response), Captcha Image.

Adsense crawler errors and robots.txt

How to fix Google AdSense crawler errors in robots.txt

Bookmark Script

Allow your users to easily bookmark your site, by clicking on a link on the page.

Password Protect With PHP

Password protect tith PHP - tutorial

PHP Mail

Sends an email.
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.