求解!! php怎么实现上传的图像存储在对应相册 php怎么实现上传的图像存储在对应的相册文件夹,而且上传后跳转到对应的页面。谢谢!! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 用 move_uploaded_file 储存在对应的文件夹,文件夹应该是你实现已经知道的,可以是定义好的变量,也可以从数据库或者别的地方提取出这个文件夹名,上传后跳转die("<script>location.href='对应页面'</script>"); 页面 shangchuan.php<form id="form3" name="form3" method="post" enctype="multipart/form-data" action="shangcphoto_do.php"> <table width="100%" height="158" border="1" align="center" cellpadding="0" cellspacing="0" bordercolor="#FFCCFF"> <tr> <td height="24" colspan="2" align="left" bordercolor="#FFCCFF" bgcolor="#FFFFFF"><table width="608" height="23" border="0" cellpadding="0" cellspacing="0"> <tr> <td width="604" height="23" align="left" bordercolor="#CCD8E6"><span class="STYLE108">相册</span><span class="STYLE104">---<span class="STYLE109">上传相片 <input type="image" src="images_photo/2.png" name="button" id="button" /> </span></span></td> </tr> </table></td> </tr> <tr> <td width="96" height="29" align="right" bordercolor="#FFCCFF"><table width="100" height="28" border="0" cellpadding="0" cellspacing="0"> <tr> <td width="100" height="30" align="right" class="STYLE5 STYLE106">选择相册:</td> </tr> </table></td> <td width="513" bordercolor="#FFCCFF"><label></label> <table width="114" height="29" border="0" cellpadding="0" cellspacing="0"> <tr> <td align="left"><select name="xiangche" id="xiangche"> <option selected="selected">信网活动</option> <option>聚会/party</option> <option>集体照片</option> <option>个人照片</option> </select></td> </tr> </table></td> </tr> <tr> <td height="28" align="right" bordercolor="#FFCCFF"><span class="STYLE21"> </span> <table width="102" height="28" border="0" cellpadding="0" cellspacing="0"> <tr> <td width="100" height="30" align="right" class="STYLE5 STYLE106"> 图像路径:</td> </tr> </table> </td> <td height="30" bordercolor="#FFCCFF"><input name="lujing" type="file" class="STYLE3" id="lujing" onchange="preview5()"/></td> <script type="text/javascript">function preview5(){ var x = document.getElementById("lujing"); if(!x || !x.value) return; var patn = /.jpg$|.jpeg$|.gif$/i; if(patn.test(x.value)){ var y = document.getElementById("img5"); if(y){ y.src = 'file://localhost/' + x.value; }else{ var img=document.createElement('img'); img.setAttribute('src','file://localhost/'+x.value); img.setAttribute('width','320'); img.setAttribute('height','240'); img.setAttribute('id','img5'); var td=document.createElement('td'); td.setAttribute('align','center'); td.appendChild(img); document.getElementById('form3').appendChild(td); } }else{ alert("您选择的似乎不是图像文件。"); } }</script> </tr> <tr> <td height="58" align="right" bordercolor="#FFCCFF"><table width="97" height="28" border="0" cellpadding="0" cellspacing="0"> <tr> <td width="100" height="30" align="right" class="STYLE5 STYLE106">图像说明:</td> </tr> </table> <label></label></td> <td height="58" bordercolor="#FFCCFF"><textarea name="shuom" cols="40" rows="5" id="shuom"></textarea></td> </tr> </table> <table width="200" height="22" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td align="center"><span class="STYLE110">图像预览</span></td> </tr> </table> </form> 数据处理 shangchuan_do.php<?phpinclude("conn.php");//$myuser = $_POST["myuser"];$xiangche = $_POST["xiangche"];$shuom = $_POST["shuom"];if(is_uploaded_file($_FILES["lujing"]["tmp_name"])){ $files=$_FILES["lujing"];//返回图片信息的数组// print_r($files);// exit(); $name=$files["name"]; $tmp_name=$files["tmp_name"]; $new_path="pic/".$name; if(!move_uploaded_file($tmp_name,$new_path)){ echo "上传失败"; exit(); } $xcSQL="insert into xiangche(xiangche,lujing,shuom) values('$xiangche','$new_path','$shuom')"; $flag=mysql_query($xcSQL,$conn)or die(mysql_error()); mysql_close($conn); if($flag>0){ echo "添加成功"; echo "<script>location.href='xinwphoto.php'</script>"; }else{ echo "添加失败"; exit(); }}else{ echo "上传文件不存在"; exit();}?> 其实只是数据库设计的问题:相册id 图片url1 http://****.jpg1 http://****.jpg1 http://****.jpg2 http://****.jpg3 http://****.jpg这就是相册1下有三张图片 2下有一张 当然数据库也不一定是这么设计 就是这么个思路!想清楚了 其实很简单的! 求高手,求围观啊,急啊 以下这个正则表达式为什么会出现这种结果? php中的数据类型转换问题 日期问题 一个论坛注册的问题 在phpMyAdmin2.53rc1基础上改的中文版想要的跟贴 如何在页面间传递数组变量?? 最近找到一份兼职,正在谈,我打算用php帮他们公司(刚刚成立,创业期)做个网站,是一个培训中心,估计说多少钱可以接受呢? $_FILES[]是在文件上传前组装的还是等上传完成后才组装的? 求教php页面只能渲染一半,为什么 正则获取源码中的url apache环境中,网络驱动器不可用
页面 shangchuan.php<form id="form3" name="form3" method="post" enctype="multipart/form-data" action="shangcphoto_do.php">
<table width="100%" height="158" border="1" align="center" cellpadding="0" cellspacing="0" bordercolor="#FFCCFF">
<tr>
<td height="24" colspan="2" align="left" bordercolor="#FFCCFF" bgcolor="#FFFFFF"><table width="608" height="23" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="604" height="23" align="left" bordercolor="#CCD8E6"><span class="STYLE108">相册</span><span class="STYLE104">---<span class="STYLE109">上传相片
<input type="image" src="images_photo/2.png" name="button" id="button" />
</span></span></td>
</tr>
</table></td>
</tr>
<tr>
<td width="96" height="29" align="right" bordercolor="#FFCCFF"><table width="100" height="28" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="100" height="30" align="right" class="STYLE5 STYLE106">选择相册:</td>
</tr>
</table></td>
<td width="513" bordercolor="#FFCCFF"><label></label>
<table width="114" height="29" border="0" cellpadding="0" cellspacing="0">
<tr>
<td align="left"><select name="xiangche" id="xiangche">
<option selected="selected">信网活动</option>
<option>聚会/party</option>
<option>集体照片</option>
<option>个人照片</option>
</select></td>
</tr>
</table></td>
</tr>
<tr>
<td height="28" align="right" bordercolor="#FFCCFF"><span class="STYLE21"> </span>
<table width="102" height="28" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="100" height="30" align="right" class="STYLE5 STYLE106"> 图像路径:</td>
</tr>
</table> </td>
<td height="30" bordercolor="#FFCCFF"><input name="lujing" type="file" class="STYLE3" id="lujing" onchange="preview5()"/></td>
<script type="text/javascript">
function preview5(){
var x = document.getElementById("lujing");
if(!x || !x.value) return;
var patn = /.jpg$|.jpeg$|.gif$/i;
if(patn.test(x.value)){
var y = document.getElementById("img5");
if(y){
y.src = 'file://localhost/' + x.value;
}else{
var img=document.createElement('img');
img.setAttribute('src','file://localhost/'+x.value);
img.setAttribute('width','320');
img.setAttribute('height','240');
img.setAttribute('id','img5');
var td=document.createElement('td');
td.setAttribute('align','center');
td.appendChild(img);
document.getElementById('form3').appendChild(td);
}
}else{
alert("您选择的似乎不是图像文件。");
}
}
</script>
</tr>
<tr>
<td height="58" align="right" bordercolor="#FFCCFF"><table width="97" height="28" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="100" height="30" align="right" class="STYLE5 STYLE106">图像说明:</td>
</tr>
</table>
<label></label></td>
<td height="58" bordercolor="#FFCCFF"><textarea name="shuom" cols="40" rows="5" id="shuom"></textarea></td>
</tr>
</table>
<table width="200" height="22" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td align="center"><span class="STYLE110">图像预览</span></td>
</tr>
</table>
</form>
数据处理 shangchuan_do.php
<?php
include("conn.php");
//$myuser = $_POST["myuser"];
$xiangche = $_POST["xiangche"];
$shuom = $_POST["shuom"];
if(is_uploaded_file($_FILES["lujing"]["tmp_name"])){
$files=$_FILES["lujing"];//返回图片信息的数组
// print_r($files);
// exit();
$name=$files["name"];
$tmp_name=$files["tmp_name"];
$new_path="pic/".$name;
if(!move_uploaded_file($tmp_name,$new_path)){
echo "上传失败";
exit();
} $xcSQL="insert into xiangche(xiangche,lujing,shuom) values('$xiangche','$new_path','$shuom')";
$flag=mysql_query($xcSQL,$conn)or die(mysql_error());
mysql_close($conn);
if($flag>0){
echo "添加成功";
echo "<script>location.href='xinwphoto.php'</script>";
}else{
echo "添加失败";
exit();
}}else{
echo "上传文件不存在";
exit();
}
?>
1 http://****.jpg
1 http://****.jpg
1 http://****.jpg
2 http://****.jpg
3 http://****.jpg这就是相册1下有三张图片 2下有一张 当然数据库也不一定是这么设计 就是这么个思路!想清楚了 其实很简单的!