基本上我想用html表单上传图片和视频文件。图像上传但视频文件没有,当我上传视频文件时显示进度....看不到任何东西..我的代码有什么问题,有人可以帮帮我吗?
<?php
if(isset($_POST['submit']) == "Submit")
{
$err = array();
@$filed = addslashes($_FILES['file']['tmp_name']);
@$img_named = addslashes($_FILES['file']['name']);
@$img_sized = getimagesize($_FILES['file']['tmp_name']);
@$imgd = addslashes(file_get_contents($_FILES['file']['tmp_name']));
function getExtension($str)
{
$i = strrpos($str,".");
if (!$i) { return ""; }
$l = strlen($str) - $i;
$ext = substr($str,$i+1,$l);
return $ext;
}
$extension = getExtension($img_named);
$extension = strtolower($extension);
$image_named_uniq = uniqid().'.'.$extension;
$upload_path_dis = 'user/manage/discussionimg/';
$diss = $_POST['type'];
$sub = $_POST['sub'];
$msg = $_POST['msg'];
$date = "On " . date("F Y h:i:s A");
if (!isset($_SESSION['uname']))
$err[] = "You need to login";
else
{
$uname = $_SESSION['uname']; //session username
if(empty($sub) && empty($msg) && empty($filed))
$err[] = "All field required";
else
{
if(empty($sub))
$err[] = "Subject Requried";
if(empty($msg))
$err[] = "Message Requried";
if(empty($filed))
$err[] ="SORRY, you have to be upload a image";
else
{
if($img_sized == FALSE)
{
$err[] ="That's not an image";
}
}
}
}
if(!empty($err))
{
foreach($err as $er)
{
echo "<font color=red>$er</font><br/>";
}
}
else
{
$sql= mysql_query("INSERT INTO discussion VALUES ('', '$imgd', '$image_named_uniq', '$diss', '$sub', '$msg', '$uname', '$date' ) ");
if(!$sql)
echo "Can't submit your discussion" . mysql_error();
if(!move_uploaded_file($_FILES['file']['tmp_name'],$upload_path_dis . $image_named_uniq))
{
die('File Not Uploading');
}
else
{
echo "Discussion was submitted";
print "<script>";
print " self.location=' " .$_SERVER['REQUEST_URI'] . " ';"; // Comment this line if you don't want to redirect
print "</script>";
}
}
}
?>
<form action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>" method="post"
name="discussion" enctype="multipart/form-data">
<table width="240" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><b>Select your image</b>
<input type="hidden" name="MAX_FILE_SIZE" value="62914560" />
<input type="file" name="file" /></td>
</tr>
<tr>
<td style="width:230;"><b>Select your Discussion</b>
<select name="type" class="td">
<?php
$sqld = mysql_query("SELECT * FROM distype");
while($row = mysql_fetch_assoc($sqld))
{
$d_id = $row['d_id'];
$diss = $row['type'];
echo "<option value='$diss'>$diss</option>";
}
?>
</select></td>
</tr>
<tr>
<td><b>Subject</b></td>
</tr>
<tr>
<td><input type="text" name="sub" value="" size="33" class="td"/></td>
</tr>
<tr>
<td><b>Message</b></td>
</tr>
<tr>
<td><textarea cols="30" rows="3" name="msg" class="td_text"></textarea></td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td><input type="submit" name="submit" value="Submit" class="submit"><br>
<td></td>
</tr>
</table>
</form>
答案 0 :(得分:0)
删除@
错误抑制因素,您将看到问题所在:
$filed = addslashes($_FILES['file']['tmp_name']);
$img_named = addslashes($_FILES['file']['name']);
$img_sized = getimagesize($_FILES['file']['tmp_name']);
$imgd = addslashes(file_get_contents($_FILES['file']['tmp_name']));
这行代码获取图像的大小:
$img_sized = getimagesize($_FILES['file']['tmp_name']);
当图像是视频文件时会发生什么?你得到一个错误。
要修复此问题,请使用MIME类型或扩展名检查文件是图像还是视频文件(不推荐)。如果是图像,请获取尺寸。如果不是,请不要大小。
答案 1 :(得分:0)
如果您打算使用上传文件大小保护,请不要使用@ $ img_sized = getimagesize($ _ FILES ['file'] ['tmp_name']);而不是使用这个
@$img_sized = $_FILES['file']['size'];
这将获取所有文件扩展名的文件大小,并删除行@ $ img_sized = getimagesize($ _ FILES ['file'] ['tmp_name']);这会给图像和视频等提供不可读或警告。
答案 2 :(得分:0)
你必须在php.ini文件中设置一些设置,如果你不这样做,那么设置.htaccess文件来增加大小
你在这里得到文章