Ad block is installed and active. Please support us by disabling it.
HomeSunday, November 19, 2017, 14:11:47
5

Upload Image With PHP

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

Show / Hide Div with CSS

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

PHP Cookies and Sessions Tutorial

PHP Cookies and Sessions Tutorials

Block Visitors From Specific IP Address

Learn How To Restrict Users From Different IP Addresses.

Smarty - Create dynamic Web Pages with PHP & MySQL

Creating Dynamic Web Pages Using Smarty and MySQL - Requirement(s): PHP Server, MySQL

ShoutBox 1.1. PHP Script

ShoutBox allows your users to post short messages on your site. The script is lightweight and very easy to install and use.

Sending HTML Email With Images - PHP Tutorial

Sending HTML Email With Images - Upload Image with PHP - Creating Dynamic Webpages Using PHP and MySQL - Select, Delete, Update..

Captcha V2 - Free PHP Script

PHP Captcha protection image Version 2, - Requirement(s): PHP Server, GD Library

Adodb Recordcount Example

RecordCount returns the number of rows in the record set.

PHP form with image upload

Advanced Contact Form with email and form field validation.It allows your visitors to send you an email directly from your website.Features: Image Upload, HTML Output, Captcha Image.

Preg_Match - PHP Email Validation

Validate email with preg_match in php
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.