SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Zealot
    Join Date
    Jul 2008
    Posts
    190
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Problem with if (isset ($_FILES['new_image']))

    Hi, I have a small problem with my script. I want to be able to add items with or without an image, and so I have part of my script that runs under this clause:

    Code:
    if (isset ($_FILES['new_image']))
    But it doesn't seem to be working as if I try to add an item without an image it is still being run and I am therefore deluged with loads of error code. Is this the right piece of code to use for this. The part of the page that this relates to is:
    Code:
    <form action="<?php echo $_server['php-self'];  ?>" method="post" enctype="multipart/form-data" id="something" class="uniForm">
    <input name="new_image" id="new_image" size="30" type="file" class="fileUpload" />
    </form>

  2. #2
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by slaterino View Post
    Hi, I have a small problem with my script. I want to be able to add items with or without an image, and so I have part of my script that runs under this clause:

    Code:
    if (isset ($_FILES['new_image']))
    But it doesn't seem to be working as if I try to add an item without an image it is still being run and I am therefore deluged with loads of error code. Is this the right piece of code to use for this. The part of the page that this relates to is:
    Code:
    <form action="<?php echo $_server['php-self'];  ?>" method="post" enctype="multipart/form-data" id="something" class="uniForm">
    <input name="new_image" id="new_image" size="30" type="file" class="fileUpload" />
    </form>
    Best bet judging by the docs would be...
    Code:
    if (isset ($_FILES['new_image']['name']))
    IMO.
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.

  3. #3
    SitePoint Zealot
    Join Date
    Jul 2008
    Posts
    190
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ah, that doesn't seem to work either. I still get the error messages. Any other ideas?

  4. #4
    From space with love silver trophy
    SpacePhoenix's Avatar
    Join Date
    May 2007
    Location
    Poole, UK
    Posts
    5,032
    Mentioned
    103 Post(s)
    Tagged
    0 Thread(s)
    Check $_FILES['new_image']['error'] for an no file uploaded error:

    From The PHP Manual
    UPLOAD_ERR_NO_FILE Value: 4; No file was uploaded.
    Community Team Advisor
    Forum Guidelines: Posting FAQ Signatures FAQ Self Promotion FAQ
    Help the Mods: What's Fluff? Report Fluff/Spam to a Moderator

  5. #5
    SitePoint Member
    Join Date
    Jan 2010
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by SpacePhoenix View Post
    Check $_FILES['new_image']['error'] for an no file uploaded error:
    PHP Code:
    if($_FILES['new_image']['error'] == 0

  6. #6
    SitePoint Mentor bronze trophy
    John_Betong's Avatar
    Join Date
    Aug 2005
    Location
    City of Angels
    Posts
    1,840
    Mentioned
    73 Post(s)
    Tagged
    6 Thread(s)
    Quote Originally Posted by slaterino View Post
    Ah, that doesn't seem to work either. I still get the error messages. Any other ideas?
    Try this and see what information is being returnedresults:
    PHP Code:

      
    echo '<pre>'// cosmetic for readability

        
    print_r($_FILES['new_image']);

      echo 
    '</pre>';

      die; 
    Learn how to be ready for The New Move to Discourse

    How to make Make Money Now with a *NEW* look

    Be sure to congratulate Patche on earning Member of the Month for July 2014


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
  •