2010-04-12 93 views
1

Uploadify是一个jQuery插件,允许轻松集成多(或单)在您的网站上传文件。它需要Flash和任何后端开发语言。一组选项允许高级用户完全自定义,但基本实现非常简单,即使编码新手也可以完成。有Uploadify电子邮件中的链接下载文件

我想问问,如果有可能发出刚刚上传wioth Uploadify的电子邮件通知文件的链接。

这里是uploadify.php代码:

<?php 
if (!empty($_FILES)) { 
    $tempFile = $_FILES['Filedata']['tmp_name']; 
    $targetPath = $_SERVER['DOCUMENT_ROOT'] . $_REQUEST['folder'] . '/'; 
    $targetFile = str_replace('//','/',$targetPath) . $_FILES['Filedata']['name']; 

    // $fileTypes = str_replace('*.','',$_REQUEST['fileext']); 
    // $fileTypes = str_replace(';','|',$fileTypes); 
    // $typesArray = split('\|',$fileTypes); 
    // $fileParts = pathinfo($_FILES['Filedata']['name']); 

    // if (in_array($fileParts['extension'],$typesArray)) { 
     // Uncomment the following line if you want to make the directory if it doesn't exist 
     // mkdir(str_replace('//','/',$targetPath), 0755, true); 

     move_uploaded_file($tempFile,$targetFile); 
     echo "1"; 
    // } else { 
    // echo 'Invalid file type.'; 
    // } 
} 

//define the receiver of the email 
$to = '[email protected]'; 
//define the subject of the email 
$subject = 'Test email'; 
//define the message to be sent. Each line should be separated with \n 
$message = "Hello World!\n\nThis is my first mail."; 
//define the headers we want passed. Note that they are separated with \r\n 
$headers = "From: [email protected]\r\nReply-To: [email protected]"; 
//send the email 
$mail_sent = @mail($to, $subject, $message, $headers); 
//if the message is sent successfully print "Mail sent". Otherwise print "Mail failed" 
echo $mail_sent ? "Mail sent" : "Mail failed"; 
?> 

回答

0

您的脚本很容易受到碰撞名。您是使用用户提供的原始名称上传的。如果多次使用相同的文件名,则会用新文件覆盖以前的版本。

而且,你盲目使用表单值,指定存储上载的位置。会发生什么,如果有人指定文件夹“../../../../../../../../../etc”和‘passwd文件’的文件名?或Windows Server” ../../../../../../../../windows/system32" 和 “ntoskrnl.exe中” 吗?如果Web服务器的错误配置来运行它的哪些用户ID,您刚刚打开机器完整的远程妥协。但即使他们不想让系统受到影响,他们也可以轻松地清除网站文档根目录中的任何文件。

话虽如此,如果你想嵌入一个链接直接下载文件,你将不得不建立一个HTML格式的电子邮件,或希望邮件客户端可以自动链接看起来像URLs的文本。构建用于mail()函数的HTML邮件是一件非常痛苦的事情。我为我的项目使用PHPMailer。它很好地工作,并允许您创建任何类型的电子邮件,你想。

0

喜欢的东西:

<?PHP 
$fileURL = 'http://' . $_SERVER['HTTP_HOST'] . $_REQUEST['folder'] . '/' . $_FILES['Filedata']['name']; 

// ... 

$message = "You can download the file from: {$fileURL}"; 

// ... 
$mail_sent = @mail($to, $subject, $message, $headers); 
//... 
+0

是的,但我该如何实现它我真的不擅长于PHP – 2010-04-12 20:30:18

+1

对不起。我不打算为您编写完整的解决方案!我的提示应该指出你正确的方向! – timdev 2010-04-12 20:42:29

+0

明白......谢谢 – 2010-04-13 14:42:47

相关问题