SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    May 2005
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Web Hosting Upload Script

    Hi, I've got a good bit of webhosting space (1 GB) and bandwidth (40 GB) and I only use a fraction of it. I'm looking for a non-ftp way for me to allow friends to upload files and such to a subdomain folder so they can have a little hosting for themselves. I'm fairly fluent in PHP and MySQL, so I'm looking for a PHP script that can (easily) allow people to upload files and to view or delete files in their directory, and be able to set it so they can only upload to their own directory (login protected i'm guessing). I'd appreciate if someone could point me in the direction of a good script (if there is one), thanks .

  2. #2
    SitePoint Guru
    Join Date
    Aug 2004
    Location
    Earth
    Posts
    737
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    Why not just create each friend a folder via ftp, Then set up a user/password via cpanel (or what eva u have) on the folders and limit each user to their own folder.

    Then they get ftp access, which would be an easy way to go about it.

  3. #3
    SitePoint Member
    Join Date
    May 2005
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Oh sorry, forgot to mention why I'm not doing that . My hosting provider only allows 1 ftp account with it's hosting package. If I want to get additional accounts it costs a good bit more ;/.

  4. #4
    SitePoint Wizard REMIYA's Avatar
    Join Date
    May 2005
    Posts
    1,351
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here is a sample code I use to uppload images to my server:

    PHP Code:
    // CONFUGURATION -START
    $serverpath "../imagesfolder"// Path to where images should be uploaded to on the server.
    $urltoimages "../imagesfolder"// Web address to where the images are accessible from.
    $maxsize "5000000";     // Example - 20000 is the same as 20kb
    // CONFIGURATION - END
    $mode $_GET['mode'];
    if (
    $mode == "") { $mode "form"; } 
    if (
    $mode == "form") {
    echo 
    "<form enctype='multipart/form-data' method='post' action='?mode=upload'>\n";
    echo 
    "<input type='file' name='file'>\n";
    echo 
    "<input type='submit' name='Submit' value='Go'>\n";
    }
     
    if (
    $mode == "upload") {
    $file $_FILES['file']['name'];
    // Allowed files extensions
    $allowedfiles[] = "gif";$allowedfiles[] = "GIF";
    $allowedfiles[] = "jpg";$allowedfiles[] = "JPG";
    $allowedfiles[] = "jpeg";$allowedfiles[] = "JPEG";
    $allowedfiles[] = "png";$allowedfiles[] = "PNG";
    $allowedfiles[] = "ico";$allowedfiles[] = "ICO";
    $allowedfiles[] = "tiff";$allowedfiles[] = "TIFF"
     
    if( 
    $_FILES['file']['size'] > $maxsize)
    {
    print 
    "File is too big - please, reduce the size and try again.";
    }
    else {
    $path "$serverpath/$file";
    foreach(
    $allowedfiles as $allowedfile) {
     
    if (
    $done <> "yes") {
    if (
    file_exists($path)) {
    echo 
    "A file with this name already exists - please rename the file and reupload.";
    exit;
    }
    }
     
    if (
    substr($file, -3) == $allowedfile) {
    move_uploaded_file$_FILES['file']['tmp_name'], "$path");
    $done "yes";
    echo 
    "<p>Your image has been successfully uploaded to our server and can be accessed using the URL provided below.</p>";
    echo 
    "<p><A href='$urltoimages/$file' target='_blank'><strong>$urltoimages/$file</strong></a></p>";
    echo 
    "<p><img src='$urltoimages/$file' border='0'>"
    }
     
    }
     
    if (
    $done <> "yes") { print "<p><b>Error:</b> Your image as not been uploaded because it is not a recognised image file. Please try again.</p>"; } 
    }

    Just change the extensions, folders, size, and do not show files, after upload.

    Success


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
  •