- 分享
- 0
- 人气
- 0
- 主题
- 14
- 帖子
- 2116
- UID
- 17791
- 积分
- 11640
- 阅读权限
- 25
- 注册时间
- 2005-9-20
- 最后登录
- 2016-9-7
- 在线时间
- 6028 小时
|
实验后还在找寻答案。。。所以先用php.com那里看到的基本的东西做了另外一个
希望大家帮我看看这个东西的几个问题:
第一个就是:该加什么才可以指定上传的图片是随机名字的呢?
第二个就是:我的图片如果要直接显示出来,是要在$message的内容那里加<img src="xxx">吗?那么该怎样让message跑html的格式呢?
以下是代码:
- <?php
- //checks if the form has been submitted
- if(isset($_POST['submit']))
- {
- for($i=0;$i<sizeof($_FILES['userfile']['name']);$i++){
- //upload directory where the file will be stored
- $uploaddir = $_SERVER['DOCUMENT_ROOT'] .'/special/model/form/mimages/';
- $uploadfile = $uploaddir . basename($_FILES['userfile']['name'][$i]);
- $uploadfiles = basename($_FILES['userfile']['name'][$i]);
- list($width, $height, $type, $attr) =
- getimagesize($_FILES['userfile']['tmp_name'][$i]);
- if (file_exists($uploadfile)) {
- //print error message
- echo $uploadfiles;
- echo "- file already exists";
- die();
- } else {
- echo "The file $uploadfiles does not exist<BR>";
- }
- if ($width > 1024 || $height > 800)
- {
- //print error message
- echo "Maximum allowed size is 1024x800 pixels";
- die();
- }
- if (move_uploaded_file($_FILES['userfile']['tmp_name'][$i], $uploadfile)) {
- echo "<BR>Image Uploaded Successfully!<BR><BR>";
- echo "<BR>Image Width: ";
- echo $width;
- echo "<BR>Image Height: ";
- echo $width;
- echo "<BR>Image type: ";
- echo $type;
- echo "<BR>Attribute: ";
- echo $attr;
- echo "<BR>";
- } else {
- //print error message
- echo "<BR>File was not successfully uploaded<BR><BR>";
- die();
- }
- $filename[i] = $uploaddir . basename($_FILES['userfile']['name'][$i]);
- echo $filename[i];
- }
- }
- $name = $_REQUEST['name'] ;
- $nickname = $_REQUEST['nickname'] ;
- $age = $_REQUEST['age'] ;
- $ic = $_REQUEST['ic'] ;
- $adds = $_REQUEST['adds'] ;
- $race = $_REQUEST['race'] ;
- $email = $_REQUEST['email'] ;
- $phone = $_REQUEST['phone'] ;
- $to = "devilbat87@gmail.com";
- $subject = "Test mail";
- $message = "
- Name:$name". "\r\n"."Nickname:$nickname"."\r\n"."Model Picture:"."Picture 01:"."\r\n"."http://www.seasonblog.com.my/special/model/form/mimages/" . $_FILES["userfile"]["name"][0]."\r\n".
- "Picture 02:"."http://www.seasonblog.com.my/special/model/form/mimages/" .$_FILES["userfile"]["name"][1]."\r\n".
- "Picture 03:"."http://www.seasonblog.com.my/special/model/form/mimages/" .$_FILES["userfile"]["name"][2];
- $headers='MIME-Version: 1.0' . "\r\n";
- $headers .= 'Content-type: text/html;charset=iso-8859-1' . "\r\n";
- $from = "$email - Be A Seasonblog Models!";
- $headers = "From: $from". "\r\n";
- mail($to,$subject,$message,$headers);
- echo "Mail Sent.";
- ?>
复制代码 |
|