Ad block is installed and active. Please support us by disabling it.
HomeWednesday, April 25, 2018, 08:53:36
5

Upload Image With PHP

Monday, February 9, 15, 01:12:13, 3 Yaers Ago Via wain, Hits: 6378
[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

PHP Tutorials

Useful step-by-step PHP tutorials for beginners

PHP Fwrite : fwrite

php write to file - how to write data to a file using the php frwite function

Jquery - Formatting International Phone Numbers

How to format international telephone numbers with jquery

PHP Write to File

PHP Write to File :: PHP Tutorial, requirement(s): PHP server

Syntax highlighting in Smarty

Syntax highlighting for Smarty - Google Code Prettify

Email to Friend - PHP Script

This form allows your visitors to suggest your site to a friend. It features an HTML email format and an admin notification email.

PHP Redirect

Header (location) redirect must be processed before any output to the browser.

Upload Image with PHP [Example2]

[Example2] Tutorial - How to upload and resize image with PHP

E-Cards 1.1. PHP Script

This script will allow your visitors to send e-cards to their friends. It features admin notification and HTML output.To use the "e-cards" script completely free , the "powered by" link at the bottom of the pages must stay intact.

PHP/MySQL Bookmarklet - PHP Tutorial

PHP/MySQL bookmarklet, bookmark current page, PHP/MySQL tutorial.
About Author

wain

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