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 6 of 6

Thread: Basic Code

  1. #1
    Banned
    Join Date
    Oct 2007
    Posts
    52
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Basic Code

    What's the minimum code required, in order to upload files to a web server securely?

  • #2
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,026
    Thanks
    2
    Thanked 315 Times in 307 Posts
    Define: "upload files to a web server securely" If you mean upload them securely, as in preventing someone from capturing the content while it is being upload, then you need to use the https:// protocol on a secure web site using an SSL certificate. If you mean secure for the web site, read this article - http://www.scanit.be/uploads/php-file-upload.pdf
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • The Following 2 Users Say Thank You to CFMaBiSmAd For This Useful Post:

    Fumigator (11-07-2007), matak (11-07-2007)

  • #3
    Banned
    Join Date
    Oct 2007
    Posts
    52
    Thanks
    0
    Thanked 0 Times in 0 Posts
    What code is needed to upload a file?

  • #4
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,026
    Thanks
    2
    Thanked 315 Times in 307 Posts
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • #5
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    CFMaBiSmAd I have a couple of questions about the PDF you gave a link to, hoping the OP does not mind the semi-hijack. Though it does directly relate to his question...

    The conclusion and ideal solution was to store uploaded files outside the web root. Is this possible when you are using a hosting company with shared resources? My webroot starts with public_html and I can go no further up the tree; it occurs to me that I am stuck because the only areas I can get to on this Linux system all stems from my webroot.

    Assuming I can place files outside the webroot, how then do I include these files in my html markup? Oh wait, I just caught on to the technique mentioned:

    PHP Code:
    <?php
    $uploaddir 
    '/var/spool/uploads/';
    $name $_GET['name'];
    readfile($uploaddir.$name);
    ?>
    So I would need to do this readfile() deal everywhere an uploaded image is used in my markup....? Hmm interesting.

  • #6
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,026
    Thanks
    2
    Thanked 315 Times in 307 Posts
    A lot of hosting accounts have a structure like -

    account_root -
    -------------- document_root (public_html)
    -------------- SSL_document_root
    -------------- statistics
    -------------- logs
    ...

    Where you could put your own folders/files.

    Any PHP function that uses a file system path can access these - include, readfile, ...

    If you don't have this structure available, you would need to put your content into a folder within your document_root and then put a .htaccess file to deny http/https access to all through the web server, but a php script can still operate on the files through the file system.
    Last edited by CFMaBiSmAd; 11-07-2007 at 08:02 PM. Reason: add couple words
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.


  •  

    Posting Permissions

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