SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Enthusiast
    Join Date
    May 2000
    Location
    Rhode Island, USA
    Posts
    35
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have an error with uploading PHP...

    I'm doing a "job application" from the book PHP programing and I have an error. Here's the story:

    You fill out the application, and you also given a chance to attach/upload your "resume" with your "job application" submission. Well, everything works fine when you have an application, it places the resume and a .txt and submission feild submissions into it's own text.

    The scrip is made that you don't need to attach your "resume," however, when I don't attach it it says:

    Warning: Unable to open 'none' for reading: No such file or directory in .../jobapp_action.php on line 79
    Error saving resume.
    However, your application will still be processed.

    Note that "Error saving resume..." is suppose to show up when a resume isn't sumitted but the "Warning" shouldn't.

    this is the portion of the code:

    echo (NL . NL);
    If ($userfile) {
    if (copy($userfile, "./temp/$applicant")) { \\ line # 79
    echo("<B>Resume received: thank you!</B>");
    } else {
    echo("<B>Error saving resume.</B>" .
    "However, your application will still be processed.");
    }
    }


    Thanks for your time,
    Alex



  2. #2
    SitePoint Author Kevin Yank's Avatar
    Join Date
    Apr 2000
    Location
    Melbourne, Australia
    Posts
    2,571
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    You can suppress the error message from the copy() function by adding an @ to the beginning of the line, as follows:

    echo (NL . NL);
    If ($userfile) {
    if (@copy($userfile, "./temp/$applicant")) { \\ line # 79
    echo("<B>Resume received: thank you!</B>");
    } else {
    echo("<B>Error saving resume.</B>" .
    "However, your application will still be processed.");
    }
    }

    copy() will still return false when no resume is submitted so that your custom error message is displayed, but the PHP error message will no longer appear.


    ------------------
    -Kevin Yank.
    http://www.SitePoint.com/
    Helping Small Business Grow Online!

  3. #3
    SitePoint Enthusiast
    Join Date
    May 2000
    Location
    Rhode Island, USA
    Posts
    35
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes, that worked! Thanks Kevin.

  4. #4
    SitePoint Wizard silver trophy Karl's Avatar
    Join Date
    Jul 1999
    Location
    Derbyshire, UK
    Posts
    4,411
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Err.. Surely Kevin a better way would be to not suppress the error message and deal with the condition rather than have code with what is technically a bug in it?

    Change
    <BLOCKQUOTE><font size="1" face="Verdana, Arial">code/font><HR><pre>If ($userfile) {[/code]
    to
    <BLOCKQUOTE><font size="1" face="Verdana, Arial">code/font><HR><pre>If ($userfile != 'none') {[/code]
    and it will work, PHP sets the file upload variable to none if their is no file to be uploaded.

    ------------------
    Karl Austin
    KDA Web Services
    "Everyone has a photographic memory. Some just don't have film."

  5. #5
    SitePoint Author Kevin Yank's Avatar
    Join Date
    Apr 2000
    Location
    Melbourne, Australia
    Posts
    2,571
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Karl,

    Indeed I considered that, but Alex's original post mentioned that he wanted the message to appear when no resume was submitted. The code does seem to be intended to work the way you describe, however.


    ------------------
    -Kevin Yank.
    http://www.SitePoint.com/
    Helping Small Business Grow Online!

  6. #6
    SitePoint Enthusiast
    Join Date
    May 2000
    Location
    Rhode Island, USA
    Posts
    35
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Karl,

    Although that code worked, I still had to add the "@" symbol in my final note for those who didn't submit a resume. Because what the program does is, if it has an attached resume, it takes it and downloads it to a temporary folder, and then renames it to "resume.txt" after a final submission is made it is moved to the final folder.

    However, when it didn't have the resume, it could create "resume.txt" or delte it... so I've gotten errors, however, adding @ character helped.

    Other than that "If ($userfile != 'none') {" worked well.

    Thanks to both of you for your help,
    Alex.


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
  •