Domain Discussion Board

Go Back   Domain Discussion Board > Web Hosting & Web Design > Scripts

 
Reply
 
LinkBack Thread Tools Display Modes
PHP : Simple Image Upload Script
Old
  (#1 (permalink))
MirandaPriestly
Member
MirandaPriestly is on a distinguished road
 
MirandaPriestly's Avatar
 
Status: Offline
Posts: 60
Points: 57.3
Bank: 3,888.5
Total Points: 3,945.8
Donate
Join Date: Feb 2008
Rep Power: 1
Smile PHP : Simple Image Upload Script - 03-17-2008, 08:07 AM

PHP Code:
<?php

echo('Image upload:


<FORM ENCTYPE="multipart/form-data" ACTION="' 
$PHP_SELF '" METHOD="POST">

Choose an image: <INPUT TYPE="file" NAME="userfile">

<INPUT TYPE="submit" VALUE="Upload">

</FORM>'
);



$path "img/";

$max_size 200000;



if (!isset(
$HTTP_POST_FILES['userfile'])) exit;



if (
is_uploaded_file($HTTP_POST_FILES['userfile']['tmp_name'])) {



if (
$HTTP_POST_FILES['userfile']['size']>$max_size) { echo "The file is too big<br />"; exit; }

if ((
$HTTP_POST_FILES['userfile']['type']=="image/gif") || ($HTTP_POST_FILES['userfile']['type']=="image/pjpeg") || ($HTTP_POST_FILES['userfile']['type']=="image/jpeg") || ($HTTP_POST_FILES['userfile']['type']=="image/png")) {



if (
file_exists($path $HTTP_POST_FILES['userfile']['name'])) { echo "This image is already uploaded.<br />"; exit; }



$res copy($HTTP_POST_FILES['userfile']['tmp_name'], $path .

$HTTP_POST_FILES['userfile']['name']);

if (!
$res) { echo "Error!<br />"; exit; } else { echo "The image was uploaded!<br />"; }



echo 
"Name: ".$HTTP_POST_FILES['userfile']['name']."<br />";

echo 
"Size: ".$HTTP_POST_FILES['userfile']['size']." bytes<br />";

echo 
"File type: ".$HTTP_POST_FILES['userfile']['type']."<br />";

echo 
"Image url: <textarea cols=\"40\">http://YOURSITE.COM/img/".$HTTP_POST_FILES['userfile']['name']."</textarea><br />";

echo 
"Preview: <img src=\"http://YOURSITE.COM/img/".$HTTP_POST_FILES['userfile']['name']."\"><br />";

} else { echo 
"You can upload only images!<br />"; exit; }

}



$my_file $HTTP_POST_FILES['userfile']['name'];

?>
For the script to work you need to create a folder called img. You also need to change http://YOURSITE.COM to your website's link

The script is made by me for one of my websites but I decided to share it with you Good luck using it Post here if you have any questions
   
Reply With Quote
Re: PHP : Simple Image Upload Script
Old
  (#2 (permalink))
P4wlIk
Executive Member
P4wlIk is an unknown quantity at this point
 
P4wlIk's Avatar
 
Status: Offline
Posts: 493
Points: 61.0
Bank: 5,483.8
Total Points: 5,544.8
Donate
Join Date: Dec 2006
Rep Power: 0
Re: PHP : Simple Image Upload Script - 03-17-2008, 08:52 AM

Yeah, good job.

I'll try this script, thanks alot!
   
Reply With Quote
Sponsored Links
Re: PHP : Simple Image Upload Script
Old
  (#3 (permalink))
djgabira
Junior Member
djgabira is on a distinguished road
 
Status: Offline
Posts: 13
Points: 189.2
Bank: 0.0
Total Points: 189.2
Donate
Join Date: May 2008
Rep Power: 0
Re: PHP : Simple Image Upload Script - 05-18-2008, 09:19 PM

nice and simple but very cool x10 from me:P
   
Reply With Quote
Re: PHP : Simple Image Upload Script
Old
  (#4 (permalink))
bokepwap
Junior Member
bokepwap is on a distinguished road
 
Status: Offline
Posts: 5
Points: 153.1
Bank: 0.0
Total Points: 153.1
Donate
Join Date: Jun 2008
Rep Power: 0
Re: PHP : Simple Image Upload Script - 06-29-2008, 09:42 AM

for simpleling, just edit http://YOURSITE.COM with
PHP Code:
$_SERVER['SERVER_NAME'
   
Reply With Quote
Re: PHP : Simple Image Upload Script
Old
  (#5 (permalink))
zuly
Platinum Member
zuly is on a distinguished road
 
zuly's Avatar
 
Status: Offline
Posts: 575
Points: 201.8
Bank: 3,695.1
Total Points: 3,897.0
Donate
Join Date: May 2008
Location: Croatia
Rep Power: 1
Re: PHP : Simple Image Upload Script - 06-29-2008, 11:07 AM

I'm not an expert in PHP i never tried it before, but how will this script react if we try to upload pictures that have the same name?
Will it change the name, i alway wanted to know that.
   
Reply With Quote
Re: PHP : Simple Image Upload Script
Old
  (#6 (permalink))
christyhl
Platinum Member
christyhl is an unknown quantity at this point
 
christyhl's Avatar
 
Status: Offline
Posts: 1,447
Points: 127.0
Bank: 816.4
Total Points: 943.3
Donate
Join Date: Apr 2008
Location: Next to the computer
Rep Power: 0
Re: PHP : Simple Image Upload Script - 07-01-2008, 11:16 AM

Do you have a guide on how to use it/ maintain it?
   

Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Points Per Thread View: 0.1
Points Per Thread: 15.0
Points Per Reply: 5.0


Similar Threads
Thread Thread Starter Forum Replies Last Post
FREE CGI Hosting blue-sky Wonderful Websites 21 04-27-2008 07:12 AM
Free php web hosting...Part 1 blue-sky Hosting Providers 24 12-22-2007 02:28 AM
Simple PHP Upload Script (Only 1 PHP file) mycek Scripts 2 11-22-2006 08:10 AM


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 ©2007, Crawlability, Inc.