Jump to content


Photo

PHP/MYSQL File Upload


  • Please log in to reply
1 reply to this topic

#1 Pbkilldezines

Pbkilldezines

    Young Padawan

  • Members
  • Pip
  • 31 posts

Posted 02 October 2004 - 05:58 PM

i now have a working submition system. It goes into phpmyadmin, how can i make it so when people submit thier tutorials the image gets uploaded somewhare. beause for now it just tells me the name of the image but i dont think its uploading it?

#2 rc69

rc69

    PHP Master PD

  • P2L Staff
  • PipPipPipPip
  • 3,827 posts
  • Gender:Male
  • Location:Here
  • Interests:Web Development

Posted 06 October 2004 - 06:47 PM

if (($_FILES['file']['type'] == "image/gif") &&
    ($_FILES['file']['size'] < 6000)){ 
	if (file_exists('images/tut/' . $_FILES['file']['name']))
    {
     die ("". $_FILES['file']['name'] . " already exists, please rename and try again.");
  } else
    copy ($_FILES['file']['tmp_name'], "PATHTOSEND".$_FILES['file']['name']) 
    or die ("Could not copy"); 
        echo "Copy Done...<br>"; 
        } 
        else {
            die ("Could Not Copy: Allowed file type- .gif, Allowed size- 6kb"); 
        }

that's the almost exact code i use for my image uploader, all you need to do is change a few things:
1. at the top where it says "images/gif", change that to the file type you want
2. at $_FILE['file']['size'], change > to either < or > (should be obvious why), and change 6000 to the amount of BYTES you want the file size to be (i.e. 6000 = 6kb)
3. where it says PATHTOSEND, change that to where you want the image to be uploaded to, make sure that directory exists (i.e. images/other/again/ or just images/)
4. change ALL of the $_FILES['file'] to be the same as a $_POST[] variable would be, just leave the 2nd []'s afterwards (i.e. $_FILES['file']['type'] to $_FILES['name_in_the_input_tag']['type'])

anymore questions, just ask




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users