SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    SitePoint Addict brain's Avatar
    Join Date
    Sep 2001
    Location
    Amsterdam
    Posts
    249
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    image file upload

    I want it to be possible to (online) upload an image (jpg or gif) to a certain directory in my site using PHP and a form. Can somebody explain me what I have to do and which codes I have to use ?

    Greetz Brain

  2. #2
    SitePoint Columnist Skunk's Avatar
    Join Date
    Jan 2001
    Location
    Lawrence, Kansas
    Posts
    2,066
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This is quite a simple process thanks to PHP's easy to use upload functions, Check out these manual pages:

    http://www.php.net/manual/en/features.file-upload.php
    http://www.php.net/manual/en/functio...oaded-file.php

  3. #3
    SitePoint Addict lveale's Avatar
    Join Date
    Jun 2001
    Location
    Dublin
    Posts
    221
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    upload script

    I found the following recently on Zend. I had to change it for my own purposes but may give you a head start.

    All original comments are intact
    PHP Code:
    <? 
    /******************************************************************** 
    *    file uploader - file uploader code snippet. 
    *   maxsize : 
    *        - you can set the maxsixe, if file size exceed maxsize it won't proceed; 
    *        - you can set the quota, if dir size exceed quota it won't proceed; 
    *        - you can set the ext, if file name extension listed on this array  it won't proceed; 

    *    Copyright (C) 2001 Wibisono Sastrodiwiryo. 
    *       This program is free software licensed under the 
    *       GNU General Public License (GPL). 

    *   CyberGL => Application Service Provider 
    *   [url]http://www.cybergl.co.id[/url] 
    *    [email]office@cybergl.co.id[/email] 

    *   $Id: uploader2.php3,v 0.2 2001/07/23 22:3:34 wibi Exp $ 
    *********************************************************************/ 
    $dir     ="/www/servers/upload"# your uploaded file dir, this dir require proper permission to write access 
    $temp     ="/tmp";  # unix system temp dir 
    $maxsize ="40960"# max 40 Kb 
    $quota   524288# define space quota 500 Kb 
    $ext     = array(".p"".php"".php3"".phtml"".shtml"); # define file extension to reject 

            
    if ($userfile AND $userfile != "none") { 
                
    $total=0
                
    $handle=opendir($dir); 
                while (
    $file readdir($handle)) { 
                    if (
    is_file("$dir/$file")) {$total+=filesize("$dir/$file");} 
                } 
                while (list(
    $key,$val) = each($ext)) { 
                    if (
    strstr($userfile_name$val)) {$invalidext=true;break;} 
                } 
                if (
    $userfile_size $maxsize) {echo "ERR: File too large";} 
                elseif (
    $invalidext) {echo "ERR: Forbiden file extension";} 
                elseif (
    $total $quota) {echo "ERR: Space quota exceeded";} 
                else { 
                    
    rename("$userfile""$temp/$userfile_name"); 
                    
    copy("$temp/$userfile_name""$dir/$userfile_name"); 
                    
    unlink("$temp/$userfile_name"); 
                    echo 
    "OK: File \"$userfile_name\" uploaded succesfully"
                }  
            } else { 
    ?> 
    <form action="<?echo $PHP_SELF?>" method=POST ENCTYPE="multipart/form-data"> 
      <table> 
        <tr> 
          <td class=navbox>Select File:</td> 
          <td>:</td> 
          <td><input type=file name=userfile></td> 
        </tr> 
        <tr> 
          <td class=navbox>&nbsp;</td> 
          <td>&nbsp;</td> 
          <td><input type=submit value=Upload></td> 
        </tr> 
    </table> 
      </form>                 
                <?}?>

  4. #4
    SitePoint Zealot
    Join Date
    Feb 2001
    Location
    rotterdam
    Posts
    130
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have this running here: http://128.241.192.9/gallery/uploader.php
    Although it doesnt work. Could you tell me why ?

    Regards,

    veedee

  5. #5
    SitePoint Addict brain's Avatar
    Join Date
    Sep 2001
    Location
    Amsterdam
    Posts
    249
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Maybe this works

    You probably have in your code:
    $dir ="/public_html/gallery";

    This must be:
    $dir ="/home/128241/public_html/gallery";

  6. #6
    SitePoint Zealot
    Join Date
    Feb 2001
    Location
    rotterdam
    Posts
    130
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    brain - thankyou very much - you are the man

    Does this pose any security risks ?

  7. #7
    SitePoint Addict brain's Avatar
    Join Date
    Sep 2001
    Location
    Amsterdam
    Posts
    249
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    no thanks

    Wat bedoel je precies met security risks ??

  8. #8
    SitePoint Zealot
    Join Date
    Feb 2001
    Location
    rotterdam
    Posts
    130
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I dont understand you. I dont live in Rotterdam anymore I used to work there.

    So no one can do anything bad with that script then ?

  9. #9
    SitePoint Addict brain's Avatar
    Join Date
    Sep 2001
    Location
    Amsterdam
    Posts
    249
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    check your personal message at "My SitePoint"

  10. #10
    SitePoint Columnist Skunk's Avatar
    Join Date
    Jan 2001
    Location
    Lawrence, Kansas
    Posts
    2,066
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you want to know about the security risks that arise from processing uploaded files check this out:

    http://www.securereality.com.au/studyinscarlet.txt


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
  •