PHP上传文件 修改上传文件 删除上传文件

上传
html页面代码

[php]<label>視頻短片</label>
<pre><input type=”file” name=”idcard_photo” id=”idcard_photo” accept=”video/mp4,video/avi”>
[/php]

PHP代码

[php]$idcard_photo_name = $_FILES[“idcard_photo”][“name”];
$idcard_photo_size = $_FILES[“idcard_photo”][“size”];
$idcard_photo_exe = substr($idcard_photo_name,strrpos($idcard_photo_name,’.’),strlen($idcard_photo_name)-strrpos($idcard_photo_name,’.’));
if($idcard_photo_exe == “.mp4” || $idcard_photo_exe == “.avi” || $idcard_photo_exe == “”)
{
if($idcard_photo_size > 1000000*1024)
{
echo “<script language=’javascript’>alert(‘影片文件不能大於1000MB’);history.go(-1);</script>”;
}
else
{
if(!empty($idcard_photo_exe))
$IDCardPhoto=getRandomNum().$idcard_photo_exe;
if(!empty($idcard_photo_name))
{
$idcard_photo_big=”你自己的图片路径”.$IDCardPhoto;
$idcard_photo_tmp = $_FILES[“idcard_photo”][‘tmp_name’];
if(copy($idcard_photo_tmp,$idcard_photo_big))
{
unlink($idcard_photo_tmp);
}
}
}
}
else
{
echo “<script language=’javascript’>alert(‘影片類型只能是: mp4/avi’);history.go(-1);</script>”;
}[/php]

删除上传文件

HTML代码

[php]<input type=”button” class=’button’ onClick=”removeIDCardPhoto()” value=”刪除”>
<script language=”javascript”>;
function removeIDCardPhoto()
{
if(confirm(“確定要刪除視頻嗎?”)==false)
return;
document.ManageForm.status.value=”removeIDCardPhoto”;
document.ManageForm.submit();
}
</script>[/php]

PHP代码

[php]if($status==”removeIDCardPhoto”)
{
$sql=” select IDCardPhoto from htx_channel where id=”.$id;
$row=$db->getRow($sql);
$idcard_photo_big=”你自己的上传路径”.$row[‘IDCardPhoto’];
if(file_exists($idcard_photo_big)&&!empty($row[‘IDCardPhoto’])) unlink($idcard_photo_big);
$sql=”update htx_channel set IDCardPhoto= where id=”.$id;
$query=$db->query($sql);
}[/php]

修改上传文件
HTML代码

[php]<input type=”file” name=”idcard_photo” id=”idcard_photo” accept=”video/mp4,video/avi”>[/php]

PHP代码

[php]$idcard_photo_name = $_FILES[“idcard_photo”][“name”];
$idcard_photo_size = $_FILES[“idcard_photo”][“size”];
$idcard_photo_exe = substr($idcard_photo_name,strrpos($idcard_photo_name,’.’),strlen($idcard_photo_name)-strrpos($idcard_photo_name,’.’));
if($idcard_photo_exe == “.mp4” || $idcard_photo_exe == “.avi” || $idcard_photo_exe == “”)
{
if($idcard_photo_size > 1000000*1024)
{
echo “<script language=’javascript’>alert(‘視頻文件不能大於1000MB’);</script>”;
}
else
{
if(!empty($idcard_photo_exe))
$IDCardPhoto=getRandomNum().$idcard_photo_exe;
if(!empty($idcard_photo_name))
{
$sql=”select IDCardPhoto from htx_channel where id=”.$id;
$row=$db->getRow($sql);
$idcard_photo_big=$UploadPath.”/”.$row[‘IDCardPhoto’];
if(file_exists($idcard_photo_big)&&!empty($row[‘IDCardPhoto’])) unlink($idcard_photo_big);
$sql=”update htx_channel set IDCardPhoto=’”.$IDCardPhoto.”‘ where id=”.$id;
$query=$db->query($sql);
if($query)
{
$idcard_photo_big=”你自己的上传路径”.$IDCardPhoto;
$idcard_photo_tmp = $_FILES[“idcard_photo”][‘tmp_name’];
if(copy($idcard_photo_tmp,$idcard_photo_big))
{
unlink($idcard_photo_tmp);
}
}
}
}
}
else
{
echo “<script language=’javascript’>alert(‘視頻文件類型只能是: mp4/avi’);</script>”;
}[/php]

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注