2

I am thinking about writing a fairly simple php script that allows a user to enter in their email address, upload a file, and enter another persons email address. After the file is uploaded, it would email both people a URL to download that file. An optional password might be nice.

This is to work around email attachment size limitations. I know there are internet services to do this, but I want the file to be uploaded to my server and within my other security controls.

Just wondering if anyone knows of a simple script out there that already exists to do this?

Scott Szretter
  • 3,938
  • 11
  • 57
  • 76

2 Answers2

2

Uploadify (http://www.uploadify.com) is an open source solution for file uploads.

[edit] This is some demo code from Uploadify:

<script type="text/javascript">
$(function() {
   $('#file_upload').uploadify({
          'uploader'  : '/uploadify/uploadify.swf',
          'script'    : '/uploadify/uploadify.php',
          'cancelImg' : '/uploadify/cancel.png',
          'folder'    : '/uploads',
          'removeCompleted' : true,
          'sizeLimit'   : 102400
       });              
    });
</script>

<div class="demo-box">
   <input id="file_upload" type="file" name="Filedata" />
   <p><a href="javascript:$('#file_upload').uploadifyUpload()">UploadFiles</a></p>        </div>
</div>
Jeremy Harris
  • 24,318
  • 13
  • 79
  • 133
  • This looks interesting, but I have not been able to find a simple working example code base that works with the current version from their site. I did not see anything in the archive, and google reveals a couple examples, but I could not get them to work with the current version. – Scott Szretter Jan 06 '12 at 12:52
  • I personally use it in one of my WordPress plugins (currently in development, but will be released open source on GitHub). See my edit above for some code from one of their demos. – Jeremy Harris Jan 06 '12 at 13:27
0

Another simple php file upload script, with password protection:
(make a yourfile.php and insert the below code. then put that yourfile.php on your website)

<?php
$pass = "YOUR_PASSWORD";
session_start();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html><head><meta http-equiv="Content-Type" content="text/html; charset=windows-1256" /></head><body>
<?php
if (!empty($_GET['action']) &&  $_GET['action'] == "logout") {session_destroy();unset ($_SESSION['pass']);}

$path_name = pathinfo($_SERVER['PHP_SELF']);
$this_script = $path_name['basename'];
if (empty($_SESSION['pass'])) {$_SESSION['pass']='';}
if (empty($_POST['pass'])) {$_POST['pass']='';}
if ( $_SESSION['pass']!== $pass) 
{
    if ($_POST['pass'] == $pass) {$_SESSION['pass'] = $pass; }
    else 
    {
        echo '<form action="'.$_SERVER['PHP_SELF'].'" method="post"><input name="pass" type="password"><input type="submit"></form>';
        exit;
    }
}
?>


<form enctype="multipart/form-data" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
Please choose a file: <input name="file" type="file" /><br />
<input type="submit" value="Upload" /></form>


<?php 

if (!empty($_FILES["file"]))
{
    if ($_FILES["file"]["error"] > 0)
       {echo "Error: " . $_FILES["file"]["error"] . "<br>";}
    else
       {echo "Stored file:".$_FILES["file"]["name"]."<br/>Size:".($_FILES["file"]["size"]/1024)." kB<br/>";
       move_uploaded_file($_FILES["file"]["tmp_name"],$_FILES["file"]["name"]);
       }
}

    // open this directory 
    $myDirectory = opendir(".");
    // get each entry
    while($entryName = readdir($myDirectory)) {$dirArray[] = $entryName;} closedir($myDirectory);
    $indexCount = count($dirArray);
        echo "$indexCount files<br/>";
    sort($dirArray);

    echo "<TABLE border=1 cellpadding=5 cellspacing=0 class=whitelinks><TR><TH>Filename</TH><th>Filetype</th><th>Filesize</th></TR>\n";

        for($index=0; $index < $indexCount; $index++) 
        {
            if (substr("$dirArray[$index]", 0, 1) != ".")
            {
            echo "<TR>
            <td><a href=\"$dirArray[$index]\">$dirArray[$index]</a></td>
            <td>".filetype($dirArray[$index])."</td>
            <td>".filesize($dirArray[$index])."</td>
                </TR>";
            }
        }
    echo "</TABLE>";
    ?>
T.Todua
  • 53,146
  • 19
  • 236
  • 237