new to uploading files...

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • jodleren

    new to uploading files...

    Well, I looked at an example from this group, tried it, and tried to
    use it - but it does not work when I do it like this in PHP4.

    <table>
    <tr><td><inpu t type="file" name="newfile" size="25"></td></tr>
    <tr><td><inpu t type="submit" name="sub_new" value="Upload"> </td></
    tr>
    </table></form>

    and in the same file, but ealier:

    if($_POST["sub_new"]!="")
    {
    print "<pre>";
    print_r($HTTP_P OST_FILES);
    echo "Uploading: ";
    echo $HTTP_POST_FILE S['newfile']['name'];
    $file=strtolowe r($HTTP_POST_FI LES['newfile']['name']);
    $uploadfile = "../somwhere/".$file;
    echo $uploadfile;
    if (move_uploaded_ file($HTTP_POST _FILES['newfile']['tmp_name'],
    $uploadfile))
    echo "<font color=\"blue\"> $file uploaded.</font><p>";
    }

    I am never able to get the filename... why?

    /S

  • Andy Jeffries

    #2
    Re: new to uploading files...

    On Wed, 14 Feb 2007 12:54:50 -0800, jodleren wrote:
    Well, I looked at an example from this group, tried it, and tried to use
    it - but it does not work when I do it like this in PHP4.
    >
    <table>
    <tr><td><inpu t type="file" name="newfile" size="25"></td></tr>
    <tr><td><inpu t type="submit" name="sub_new" value="Upload"> </td></
    tr>
    </table></form>
    What's the opening form tag look like?

    That is important...

    Cheers,


    Andy



    --
    Andy Jeffries MBCS CITP ZCE CMDEV
    Zend Certified Engineer
    Certified MySQL Developer
    gPHPEdit Lead Developer - http://www.gphpedit.org

    Comment

    • jodleren

      #3
      Re: new to uploading files...

      On Feb 15, 11:28 am, Andy Jeffries <n...@andyjeffr ies.co.ukwrote:
      On Wed, 14 Feb 2007 12:54:50 -0800, jodleren wrote:
      Well, I looked at an example from this group, tried it, and tried to use
      it - but it does not work when I do it like this in PHP4.
      >
      <table>
      <tr><td><inpu t type="file" name="newfile" size="25"></td></tr>
      <tr><td><inpu t type="submit" name="sub_new" value="Upload"> </td></
      tr>
      </table></form>
      >
      What's the opening form tag look like?
      <form method=post name='myform' action='the_fil e_itself'>

      BR
      S


      Comment

      • Rik

        #4
        Re: new to uploading files...

        On Thu, 15 Feb 2007 13:28:32 +0100, jodleren <sonnich@hot.ee wrote:
        On Feb 15, 11:28 am, Andy Jeffries <n...@andyjeffr ies.co.ukwrote:
        >On Wed, 14 Feb 2007 12:54:50 -0800, jodleren wrote:
        Well, I looked at an example from this group, tried it, and tried to
        >use
        it - but it does not work when I do it like this in PHP4.
        >>
        <table>
        <tr><td><inpu t type="file" name="newfile" size="25"></td></tr>
        <tr><td><inpu t type="submit" name="sub_new" value="Upload"> </td></
        tr>
        </table></form>
        >>
        >What's the opening form tag look like?
        >
        <form method=post name='myform' action='the_fil e_itself'>
        <form enctype="multip art/form-data" method="post" action="/">

        Enctype is important.
        --
        Rik Wasmus

        Comment

        • Daniele

          #5
          Re: new to uploading files...

          i had a similar problem in safari 2.0.3 resolved in 2.0.4
          just close the tag files
          <input type="file" name="newfile" size="25"/>

          maybe like this
          <form enctype="multip art/form-data" action="uploade r.php" method="POST">
          <input type="hidden" name="MAX_FILE_ SIZE" value="100000" />
          <input name="uploadedf ile" type="file" />
          <input type="submit" value="Upload File" />
          </form>

          jodleren wrote:
          On Feb 15, 11:28 am, Andy Jeffries <n...@andyjeffr ies.co.ukwrote:
          >On Wed, 14 Feb 2007 12:54:50 -0800, jodleren wrote:
          >>Well, I looked at an example from this group, tried it, and tried to use
          >>it - but it does not work when I do it like this in PHP4.
          >><table>
          >> <tr><td><inpu t type="file" name="newfile" size="25"></td></tr>
          >> <tr><td><inpu t type="submit" name="sub_new" value="Upload"> </td></
          >>tr>
          >></table></form>
          >What's the opening form tag look like?
          >
          <form method=post name='myform' action='the_fil e_itself'>
          >
          BR
          S
          >
          >

          Comment

          • jodleren

            #6
            Re: new to uploading files...

            On Feb 15, 2:52 pm, Rik <luiheidsgoe... @hotmail.comwro te:
            On Thu, 15 Feb 2007 13:28:32 +0100, jodleren <sonn...@hot.ee wrote:
            On Feb 15, 11:28 am, Andy Jeffries <n...@andyjeffr ies.co.ukwrote:
            On Wed, 14 Feb 2007 12:54:50 -0800, jodleren wrote:
            Well, I looked at an example from this group, tried it, and tried to
            use
            it - but it does not work when I do it like this in PHP4.
            >
            <table>
            <tr><td><inpu t type="file" name="newfile" size="25"></td></tr>
            <tr><td><inpu t type="submit" name="sub_new" value="Upload"> </td></
            tr>
            </table></form>
            >
            What's the opening form tag look like?
            >
            <form method=post name='myform' action='the_fil e_itself'>
            >
            <form enctype="multip art/form-data" method="post" action="/">
            >
            Enctype is important.
            Thanks. I asume that it does not stop me from checking other actions
            in my form?
            I cannot test yet :-)

            BR
            Sonnich

            Comment

            • jodleren

              #7
              Re: new to uploading files...

              On Feb 15, 2:51 pm, Daniele <"dmassaiu{["@]}yahoo.co.ukwro te:
              i had a similar problem in safari 2.0.3 resolved in 2.0.4
              just close the tag files
              <input type="file" name="newfile" size="25"/>
              >
              maybe like this
              <form enctype="multip art/form-data" action="uploade r.php" method="POST">
              <input type="hidden" name="MAX_FILE_ SIZE" value="100000" />
              <input name="uploadedf ile" type="file" />
              <input type="submit" value="Upload File" />
              </form>
              Will test.
              Question: I see the MAX_FILE_SIZE, have seen it elsewhere.... any
              special reason for that?

              BR
              Sonnich

              Comment

              • Rik

                #8
                Re: new to uploading files...

                On Thu, 15 Feb 2007 13:52:40 +0100, jodleren <sonnich@hot.ee wrote:
                <form method=post name='myform' action='the_fil e_itself'>
                >>
                ><form enctype="multip art/form-data" method="post" action="/">
                >>
                >Enctype is important.
                >
                Thanks. I asume that it does not stop me from checking other actions
                in my form?
                I cannot test yet :-)
                Any other normal postvalue is just handled fine indeed.
                --
                Rik Wasmus

                Comment

                • Daniele

                  #9
                  Re: new to uploading files...

                  jodleren wrote:
                  On Feb 15, 2:51 pm, Daniele <"dmassaiu{["@]}yahoo.co.ukwro te:
                  >i had a similar problem in safari 2.0.3 resolved in 2.0.4
                  >just close the tag files
                  ><input type="file" name="newfile" size="25"/>
                  >>
                  >maybe like this
                  ><form enctype="multip art/form-data" action="uploade r.php" method="POST">
                  ><input type="hidden" name="MAX_FILE_ SIZE" value="100000" />
                  ><input name="uploadedf ile" type="file" />
                  ><input type="submit" value="Upload File" />
                  ></form>
                  >
                  Will test.
                  Question: I see the MAX_FILE_SIZE, have seen it elsewhere.... any
                  special reason for that?
                  >
                  BR
                  Sonnich
                  >
                  from http://www.developershome.com/wap/wa....asp?page=php3

                  In the above HTML/XHTML code, the MAX_FILE_SIZE form field states that
                  the file to be uploaded should not be larger than 1048576 bytes. If a
                  browser supports this form field, it will not allow the user to choose a
                  file that is larger than 1048576 bytes. So, the user does not have to
                  wait for a file to upload to the server in order to find out whether it
                  is too large or not. However, at the time of writing, we cannot find any
                  WAP browsers that support the MAX_FILE_SIZE form field. Also, both IE 6
                  and Firefox 2.0 do not understand this form field.

                  Comment

                  • Daniele

                    #10
                    Re: new to uploading files...

                    Rik wrote:
                    On Thu, 15 Feb 2007 13:52:40 +0100, jodleren <sonnich@hot.ee wrote:
                    ><form method=post name='myform' action='the_fil e_itself'>
                    >>>
                    >><form enctype="multip art/form-data" method="post" action="/">
                    >>>
                    >>Enctype is important.
                    >>
                    >Thanks. I asume that it does not stop me from checking other actions
                    >in my form?
                    >I cannot test yet :-)
                    >
                    Any other normal postvalue is just handled fine indeed.
                    --Rik Wasmus
                    try this
                    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
                    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
                    <html xmlns="http://www.w3.org/1999/xhtml">
                    <head>
                    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
                    <title>Untitl ed Document</title>
                    </head>
                    <?
                    if (isSet($_POST['add'])) {
                    $uploaddir = '.';
                    $uploadfile = $uploaddir . basename($_FILE S['file']['name']);

                    echo '<pre>';
                    if (is_uploaded_fi le($_FILES['file']['tmp_name'])) {
                    echo "file upload in " . $_FILES['file']['tmp_name'] ."\n";
                    }
                    if (move_uploaded_ file($_FILES['file']['tmp_name'], $uploadfile)) {
                    echo "File was successfully uploaded.\n";
                    } else {
                    echo "File was NOT successfully uploaded.\n";
                    }

                    echo 'Here is some more debugging info:';
                    print_r($_FILES );

                    print "</pre>";
                    }
                    ?>
                    <body>
                    <form action="<? echo $_SERVER['PHP_SELF']; ?>" method="post"
                    enctype="multip art/form-data">
                    <p>Pictures:
                    <input type="file" name="file" />
                    <input name="add" type="submit" id="add" value="add" />
                    </p>
                    </form>
                    </body>
                    </html>

                    Comment

                    • Rik

                      #11
                      Re: new to uploading files...

                      On Thu, 15 Feb 2007 14:18:46 +0100, Daniele <"dmassaiu{["@]}yahoo.co.uk>
                      wrote:
                      Rik wrote:
                      >On Thu, 15 Feb 2007 13:52:40 +0100, jodleren <sonnich@hot.ee wrote:
                      >><form method=post name='myform' action='the_fil e_itself'>
                      >>>>
                      >>><form enctype="multip art/form-data" method="post" action="/">
                      >>>>
                      >>>Enctype is important.
                      >>>
                      >>Thanks. I asume that it does not stop me from checking other actions
                      >>in my form?
                      >>I cannot test yet :-)
                      > Any other normal postvalue is just handled fine indeed.
                      try this
                      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
                      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
                      New code, where is it transitioning from? New code should always be
                      strict...
                      <html xmlns="http://www.w3.org/1999/xhtml">
                      <head>
                      <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"
                      />
                      <title>Untitl ed Document</title>
                      </head>
                      Open the body tag here, <preis illegal in the <head>
                      <?
                      if (isSet($_POST['add'])) {
                      $uploaddir = '.';
                      $uploadfile = $uploaddir . basename($_FILE S['file']['name']);
                      >
                      echo '<pre>';
                      if (is_uploaded_fi le($_FILES['file']['tmp_name'])) {
                      echo "file upload in " . $_FILES['file']['tmp_name'] ."\n";
                      }
                      if (move_uploaded_ file($_FILES['file']['tmp_name'], $uploadfile)) {
                      echo "File was successfully uploaded.\n";
                      } else {
                      echo "File was NOT successfully uploaded.\n";
                      }
                      What about:
                      switch($_FILES['file']['error']){
                      case UPLOAD_ERR_OK:
                      echo 'upload was fine';
                      if(move_uploade d_file($_FILES['file']['tmp_name'], $uploadfile)){
                      echo 'file was succesfully moved';
                      } else {
                      echo 'file could not be moved to '.$uploadfile;
                      }
                      break;
                      case UPLOAD_ERR_INI_ SIZE:
                      echo 'file was bigger then allowed in php.ini';
                      break;
                      case UPLOAD_ERR_FORM _SIZE:
                      echo 'file was bigger then allowed in MAX_FILE_SIZE in the form';
                      break;
                      case UPLOAD_ERR_PART IAL:
                      echo 'file was only partially uploaded';
                      break;
                      case UPLOAD_ERR_NO_F ILE:
                      echo 'no file was uploaded';
                      break;
                      case UPLOAD_ERR_NO_T MP_DIR:
                      echo 'no temporary folder to write upload to';
                      break;
                      case UPLOAD_ERR_CANT _WRITE
                      echo 'problem writing file to disk';
                      break;
                      case UPLOAD_ERR_EXTE NSION
                      echo 'file-upload stopped by extention';
                      break;
                      default:
                      echo 'Unknown error';
                      print_r($_FILES );
                      }

                      Seems a bit more informative.
                      --
                      Rik Wasmus

                      Comment

                      Working...