uploading a file with php

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • arcticmouse
    New Member
    • Oct 2008
    • 2

    uploading a file with php

    this is probably a total newbie question, but i can seem to figure it out.
    when i run this code it gives me this error:
    Undefined index: work in FILENAME on line 3... which is the file-to-be-uploaded name.

    i copied this from php.net, so i thought it should work. then i copied the simpler code from w3 schools, and that gave me the same error. but, here is my html and php:

    [HTML]<form action="process .php" method="POST">
    Picture: <br>
    <input type="hidden" name="MAX_FILE_ SIZE" value="25000" />
    <input name="work" type="file" >
    <br><br>
    <input type="submit" value="Submit">[/HTML]

    [PHP]<?php
    $target_path = "/uploads/";
    $target_path = $target_path. basename( $_FILES['work']['name']);

    if(move_uploade d_file($_FILES['work']['tmp_name'], $target_path)) {
    echo "The file ". basename( $_FILES['work']['name']).
    " has been uploaded";
    } else{
    echo "There was an error uploading the file, please try again!";
    }
    ?>[/PHP]

    thanks in advance to anyone who stoops to answer my easy question!

    oh, also, it might help to know that i am using brinkster, and their php.ini file does not allow me to do many things (like send email). which sucks for me, since i obviously am not the most knowledgable in php. also, this is a page for someone else, so moving the website from brinkster to another server is not an option! :)
  • Markus
    Recognized Expert Expert
    • Jun 2007
    • 6092

    #2
    You haven't given the form's enctype.

    Code:
    <form ... enctype="multipart/form-data">
    ...
    </form>

    Comment

    • arcticmouse
      New Member
      • Oct 2008
      • 2

      #3
      Originally posted by Markus
      You haven't given the form's enctype.

      Code:
      <form ... enctype="multipart/form-data">
      ...
      </form>

      thank you so much markus! that was it! you sir, are most excellent! have a wonderful week!

      Comment

      • Markus
        Recognized Expert Expert
        • Jun 2007
        • 6092

        #4
        Originally posted by arcticmouse
        thank you so much markus! that was it! you sir, are most excellent! have a wonderful week!
        Aha! Well thank you for such a warm thank you!

        See you around.

        Markus.

        Comment

        • zabsmarty
          New Member
          • Feb 2007
          • 25

          #5
          change this
          <form action="process .php" method="POST">

          into
          <form enctype="multip art/form-data" action="process .php" method="POST">

          Comment

          • Markus
            Recognized Expert Expert
            • Jun 2007
            • 6092

            #6
            Originally posted by zabsmarty
            change this
            <form action="process .php" method="POST">

            into
            <form enctype="multip art/form-data" action="process .php" method="POST">
            Ok, are you just taking my answers and putting them into different words?

            Comment

            Working...