Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Oct 2002
    Posts
    34
    Thanks
    0
    Thanked 0 Times in 0 Posts

    making image upload an option

    Hi. I had a script made for adding a product to a database which includes linking to an image that is uploaded to a folder. This is all working well. Only thing is the script will not proceed if the user does not choose an image to upload. I want to make this a choice not a requirement. The relevant part of the code is below:-



    PHP Code:
    if(isset($_FILES['files'])) {
    if(
    $_FILES['files']['type'] == 'image/gif' ||
              
    $_FILES['files']['type'] == 'image/pjpeg' ||
              
    $_FILES['files']['type'] == 'image/jpeg' ||
              
    $_FILES['files']['type'] == 'image/jpg' &&
              
    is_uploaded_file($_FILES['files']['tmp_name']) == true) {
                    
    move_uploaded_file($_FILES['files']['tmp_name'],'images/uploads/'$_FILES['files']['name']); 
                    
    $sql .= " ,imgname = '"DBUploadDir $_FILES['files']['name'] . "'";
              } else {
                  die(
    'invalid image type. make sure your image type is a gif or jpeg. or the file is not a uploaded file.<br>
                  please use your back button and correct this.'
    );
              }
        } 
    I was hoping someone could help with what I would need to do to make this an option. Thanking you, Sheryll.

  • #2
    Mega-ultimate member
    Join Date
    Jun 2002
    Location
    Winona, MN - The land of 10,000 lakes
    Posts
    1,855
    Thanks
    1
    Thanked 45 Times in 42 Posts
    This may be better for the php forum, but here's my guess,

    If you're posting the form with an element name "files" even if the user doen't enter anything the variable "files" will be set, only it will be set to NULL or "". Add a check for those values.

    ie
    Code:
    if(isset($_FILES['files']) && $_FILES!="") {
    Hope this helps

  • #3
    New Coder
    Join Date
    Oct 2002
    Posts
    34
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks for your reply. I gave it a try but it didn't work so will post in php forum like you suggest.

    Thanks, Sheryll.


  •  

    Posting Permissions

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