SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Zealot
    Join Date
    May 2001
    Posts
    141
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    File upload H E L P!

    Hey there,

    I have been having a problem uploading files into a directory on my server using PHP. I am hoping someone will know what is wrong with my code. I am posting the File form input field code...then on submit the file calls PHP_SELF, and so I will post the rest of the code after that...much thanks!

    Form field:
    <P> Upload Document File <BR>
    </P>
    <P>File to Upload
    <INPUT TYPE="hidden" name="MAX_FILE_SIZE"
    value="2000000">
    <INPUT NAME="userfile" TYPE="file" size=35></P>
    <P>Please specify whether the file is in HTML or PDF format:
    <INPUT NAME="html" TYPE="checkbox">HTML file
    <INPUT NAME="pdf" TYPE="checkbox">PDF file
    <P><INPUT TYPE=SUBMIT NAME="submit" VALUE="SUBMIT"></P>

    Upload instructions and code:

    PHP Code:
    if ($submit): // A new article has been entered
                  // using the form below.

    $html = isset ($html);
      
    $pdf  = isset ($pdf);

      if (!
    $html && !$pdf) {
        echo(
    "<P>You must choose a <u>file</u> type " .
             
    "for this document. Click 'Back' " .
             
    "and try again. </P>");
        exit();
      }

          if (
    $userfile) { 
          
          if (
    $html) {
            
             if (
    $type=="1") {
                  
    $html="http://www.somewhere.ca/assets/documents/articles/$userfile_name";
                  if (
    copy($userfile,"../documents/articles/$userfile_name"))
                     echo(
    "<B> File successfully uploaded</B>");
                  else
                    echo(
    "<B>Error uploading file. However, document details will still be entered into the database. Please upload file manually to the articles folder.</B>");   
             } else if (
    $type=="2") {
                  
    $html="http://www.somewhere.ca/assets/documents/regulations/$userfile_name";
                  if (
    copy($userfile,"../documents/regulations/$userfile_name"))
                     echo(
    "<B> File successfully uploaded</B>");
                  else
                     echo(
    "<B>Error uploading file. However, document details will still be entered into the database. Please upload file manually to the educational folder.</B>");
                         

             } else if (
    $type=="3") {
                  
    $html="http://www.somewhere.ca/assets/documents/educational/$userfile_name";
                  if (
    copy($userfile,"../documents/educational/$userfile_name"))
                     echo(
    "<B> File successfully uploaded</B>");
                  else
                     echo(
    "<B>Error uploading file. However, document details will still be entered into the database. Please upload file manually to the regulations folder.</B>");
             } 
    // end of types
          
    // end of html if statement

          
    if ($pdf) {
            
             if (
    $type=="1") {
                  
    $pdf="http://www.somewhere.ca/assets/documents/articles/$userfile_name";
                  if (
    copy($userfile,"../documents/articles/$userfile_name"))
                     echo(
    "<B> File successfully uploaded</B>");
                  else
                     echo(
    "<B>Error uploading file. However, document details will still be entered into the database. Please upload file manually to the articles folder.</B>");
             } else if (
    $type=="2") {
                  
    $pdf="http://www.somewhere.ca/assets/documents/regulations/$userfile_name";
                  if (
    copy($userfile,"../documents/regulations/$userfile_name"))
                     echo(
    "<B> File successfully uploaded</B>");
                  else
                     echo(
    "<B>Error uploading file. However, document details will still be entered into the database. Please upload file manually to the educational folder.</B>");

             } else if (
    $type=="3") {
                  
    $pdf="http://www.somewhere.ca/assets/documents/educational/$userfile_name";
                  if (
    copy($userfile,"../documents/educational/$userfile_name"))
                     echo(
    "<B> File successfully uploaded</B>");
                  else
                     echo(
    "<B>Error uploading file. However, document details will still be entered into the database. Please upload file manually to the regulations folder.</B>");
             } 
    // end of types
          
    // end of pdf if statement
     
       
    // end of userfile if statement

    unlink($userfile);

    $html htmlspecialchars($html);
    $pdf  htmlspecialchars($pdf); 
    Thanks again!
    Last edited by XGuy; Aug 29, 2001 at 05:08.

  2. #2
    SitePoint Addict
    Join Date
    Apr 2001
    Location
    None
    Posts
    254
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Wow, that's way too much code for just uploading a file

    Your main problem is:

    PHP Code:
    (copy($userfile,"../documents/articles/$userfile_name")) 
    You can't copy it to ../blah_blah, it needs to be the full path - such as /home/user/www/document/articles/$userfile_name


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •