PHP Learn How To Upload Images Make PHP Script Code Tutorial Guide Steps
php learn how to upload images make php script code tutorial guide steps
php, learn, how, to, upload, images, make, php, script, code, tutorial, guide, steps
PHP Learn How To Upload Images Make PHP Script Code Tutorial Guide Steps
Post Description: php learn how to upload images make php script code tutorial guide steps
POST# 380
Posted On: Fri Feb 29, 2008 12:01 pm
web hosting
Topic: PHP Learn How To Upload Images Make PHP Script Code Tutorial Guide Steps
yesterday i wanted to know how those websites do it so that they allow their visitors to upload pictures,images,pic,photos or photographs from their visitors into their website. well, i contacted our support team at www.webune.com and they were able to explain it to me. so i won't forget how to do thin in the future i am writing this small tutorial with its very own script code to show it works.

the first thing its to make sure you have PHP on your webstie. if you don't, you can visit www.webune.com and signup with one of their PHP plans. I recommend them to all my customers, Webune has excellent service and support.

step 2 is to make open your favorite text editor. since i am using windows xp, i will be using notepad.exe

step 3 copy and paste the following code into a blank notepad:



     Code:
<?
######################################################################
############ ############
############ Image Upload PHP Script by Wallpaperama.com ############
############ for help go to: http://www.wallpaperama.com ############
############ ############
######################################################################
?>
<html>
<head>
<title>Image File Upload With PHP Example Code By Wallpaperama</title>
</head>

<body>
<?php if (isset($_REQUEST['submit']))
{
echo"<h1>Image Upload Successfully!</h1><hr>";
?>
<p><img src="<? echo"images/$superdat_name"; ?>" ></p>
<p><em><strong>File Uploaded Location:</strong></em><br>
<input name="textfield" type="text" value="<? echo"images/$superdat_name"; ?>" size="100">
</p>
<p><a href="<?php echo $_SERVER['REQUEST_URI']; ?>">Upload Another Image &gt;&gt;</a></p>
<p><strong>Help Us. If you learned from this script and would like to help us, please link to our site at :</strong> <a href="http://www.wallpaperama.com">http://www.wallpaperama.com</a></p>
<p><strong>If you would like to trade links with us, <a href="http://www.wallpaperama.com/link-exchange.php">click here</a></strong> <?
copy("$superdat", "images/$superdat_name") or die("Couldn't copy file.");
}
else
{
?>
</p>
<h1>Image File Upload With PHP Example Code By Wallpaperama</h1><hr>
<p>This is an example PHP script to show you how you can write a script to allow you or your visitors to be able to upload image files to your website. </p>
<FORM ACTION="<?php echo $_SERVER['REQUEST_URI']; ?>" METHOD="POST" ENCTYPE="multipart/form-data">
<CENTER>
<TABLE WIDTH=450 BORDER=0 CELLPADDING=0 CELLSPACING=0 id=news>

<tr >
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr >
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr >
<td width=113>
<p align=right><b>Upload Image : </b> </td>
<td width=289>
<p><input type=file name="superdat" size=30></p>
</td>
</tr>

<tr>
<td colspan=2 align=center>&nbsp; </td>
</tr>


</TABLE>
</CENTER>
<DIV ALIGN=CENTER>
<P STYLE="margin-bottom: 0in"><INPUT TYPE=SUBMIT NAME="submit" VALUE="Upload Image"></P>
</DIV>
</FORM>
<? } ?>
<p>&nbsp;</p>
<p align="center">Hosting And Support For This Script Provided By <a href="http://www.webune.com">Webune.com</a> </p>
</body>
</html>



step 4 save this file as upload.php (if you are going to be using notepad like i am, make sure when you save it put quotes like this: "upload.php" otherwise, notepad will save the file as notepad.php.txt)

step 5. FTP to your website and create a directory (folder) called upload.

step 6. once you have created a directory called "upload" (withoug quotes) upload the upload.php file to this new directory.

step 7. now create a new directory called image and make sure you give it write permission of 777. if you dont' do this step, the file will never upload to your website and this script is not going to work. and you will get an error

step 8. now you should have a file called upload.php and a directory called images in the upload directory. Open the upload.php file with your browser (example: http://www.yourdomain.com/upload/upload.php and try uploading an image. try uploading a small .gif or .jpg or .jpeg file.

step 9. if everything goes well, you should have an image file in the images directory

NOTE: this is a very basic script. there are other things you should use to make it more secure, like only allowing image files and limiting the image size for example, but that's another tutorial, the purpose of this tutorial was to teach you or give you and idea of how it works. later you can customize it and make it more secure and perhaps post your code ont his thread to share your knowledge with other just like i am doing today with you.

DONE


Tue Feb 20, 2007 12:10 am
1
Sheeba
Reply #978
Your code is very Nice But Plz guide me if i wana Add Same image in two Folders what steps are required for that ?????
Tue Feb 20, 2007 8:09 am
2
hostman
Reply #979
just look for the line : copy("$superdat", "images/$superdat_name") or die("Couldn't copy file.");
then add this after: copy("$superdat", "NEW_DIRECTORY/$superdat_name") or die("Couldn't copy file.");

change NEW_DIRECTORY to whatever you want. basically all you are doing is running the copy function two times but on two different Folders (Directories)
Tue Feb 20, 2007 11:01 pm
3
sheeba
Reply #980
Thank you so much for helping....
Tue Feb 27, 2007 8:39 am
4
wavehead
Reply #981
that code didn't work for me
Fri Apr 13, 2007 8:04 pm
5
Frederick
Reply #982
post image
Hello Sir how can i set folder permision to 777? i use xamp then i run this sample in localthost only. the problem is that i dont know how to set folder permision to 777
Fri Apr 13, 2007 8:21 pm
6
file permit
Reply #983
CLICK HERE TO LEARN HOW YOU CAN CHANGE FILE PERMISSION ON YOU FOLDERS

What do you think?

* name:  

* email:  

* Please enter comments:


Receive Replies on my Comments
(An email will be sent to you when someone replies to your comments)

Add image to comments
yes no             upload