HomeSunday, June 24, 2018, 01:39:53
1

Upload Image with PHP [Example2]

Monday, February 9, 15, 01:07:57, 3 Yaers Ago Via wain, Hits: 6129
[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

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..

Site Recommendation

This script will allow your visitors to recommend your site to their friends.

Images In Textarea - CSS

Tutorial Images in Textarea

Link Base 2.0.

Manage your links using a MySQL database. It features easy install, user submission, and an admin panel to add, edit and remove categories and links.

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

PHP Form Validation

PHP form validation :: PHP tutorial, requirement(s): PHP Server

Upload File with PHP

Basic file uploading with PHP

How to insert new line (IP Address) with fwrite

How to insert new line (IP Address) with fwrite, Get IP address and write to file.

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.

PHP Tutorials

Useful step-by-step PHP tutorials for beginners
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.