Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 8 of 8
  1. #1
    Junior Member
    Join Date
    Dec 2005
    Location
    Vilnius, Lithuania
    Posts
    17
    Member #
    12192
    Hello webdesignforums,

    Haven't been here for ages (been retired from sociality to master css). Great to see the new (at least to me) design. it's really user-friendly, well done!

    Want to ask for help with php file upload script. I need to add functionality to my html form - it should:
    1) take a file from user's computer;
    2) check file extension and allow only certain extension (ms word .doc);
    3) check file size and allow files under 100kb;
    4) send the file as an e-mail attachment

    I don't know php well enough to write such script myself so tryed using different ready scripts but they all had functionality i don't need and didn't do some basic things. can you please recommend me something and/or ideally give such script

    Thanks a lot, any help is greatly appriciated.

  2.  

  3. #2
    Senior Member
    Join Date
    Jun 2005
    Location
    Atlanta, GA
    Posts
    4,146
    Member #
    10263
    Liked
    1 times
    If you do a search in various places, especially in the tutorials section, I think you'll find a few things that fit your needs

  4. #3
    WDF Staff mlseim's Avatar
    Join Date
    Apr 2004
    Location
    Cottage Grove, Minnesota
    Posts
    7,715
    Member #
    5580
    Liked
    717 times
    I guess I don't have a full script for you, but this is what
    you should look into ...

    A script to upload the file to a directory,
    then, the script sends an email with that file in the directory,
    then, the script "unlinks" or deletes the file in the directory.

    So in summary, you are looking for two scripts ...
    1) form with file upload
    2) email with attachment

    Put them together.


  5. #4
    Member
    Join Date
    Apr 2007
    Posts
    96
    Member #
    15165
    I wrote this very quickly that would handle the file upload checks you asked for. However, it would take some more effort to email the resulting file, which I don't have time for a the moment.

    Code:
    <?php
    
    $error = array();
    
    if(!isset($FILES['userfile']))
        $error["userfile"] = "No file was uploaded.";
    
    if(!count($error))
    {
        $filename = basename($_FILES['userfile']['name']);
    
        $temp = explode(".", $filename);
        $extension = array_pop($temp);
    
        if(strtolower($extension) != "jpg")
        (
            if(strtolower($extension) != "doc")
                $error["extension"] = "You can only upload a jpg or doc file.";
        }
    
        if($_FILES['userfile']['size'] > 1000)
            $error["filesize"] = "The file submitted is too large."
    }
    
    if(!count($error))
    {
        $uploaddir = '/var/www/uploads/';
        $uploadfile = $uploaddir . basename($_FILES['userfile']['name']);
    
        move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)
    }
    
    ?>

  6. #5
    Senior Member Steax's Avatar
    Join Date
    Dec 2006
    Location
    Bandung, Indonesia
    Posts
    1,207
    Member #
    14572
    Beware, though, that simply making sure the file is a ".doc" extension might be unsafe. I think the safest method would be to only accept zip files, as they are generally the safest method to store files.
    Note on code: If I give code, please note that it is simply sample code to demonstrate an effect. It is not meant to be used as-is; that is the programmer's job. I am not responsible to give you support or be held liable for anything that happens when using my code.

  7. #6
    Junior Member
    Join Date
    Dec 2005
    Location
    Vilnius, Lithuania
    Posts
    17
    Member #
    12192
    Hello,

    Actually there is a working script which accepts any file, creates a zip file and sents it as an attachment. I only need to add couple of checks which look like "if condition" wrappers. It is that simple. Unfortunately all my atempts to add these conditions (file type and size) ruined the script so I failed to get it working.

    Regarding searching... i've done quite a thorough search but all the examples either have a lot more than needed or too primitive.

    That's why i'm asking for a ready solution. it seems to be so basic (if you know php) and so useful that i expect many webmasters might have it in their script libraries. You really don't want to write such thing from scratch each time you are putting up an upload form.

    I can also show you the script I am trying to modify... if that's easier?

  8. #7
    Junior Member
    Join Date
    May 2007
    Location
    United Kingdom
    Posts
    2
    Member #
    15216
    This is probably overkill but may do what you want (and it's free)
    http://www.uploadscript.net/

  9. #8
    Junior Member
    Join Date
    Dec 2005
    Location
    Vilnius, Lithuania
    Posts
    17
    Member #
    12192
    Quote Originally Posted by mikal42
    This is probably overkill but may do what you want (and it's free)
    http://www.uploadscript.net/
    Using it for my small purpose would be like shooting sparrows from a cannon. Also (as i understand) the idea behind such scripts is to walk around file size limitations imposed by server configuration - which is opposite to what i need.
    Thank you mikal42, might use your link in future projects.


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 07:35 AM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com