一个网页main.php,里面有个iframe,能否在iframe上传成功后,在main.php文本框中获得文件上传后的路径,main.php不能刷新,否则其他资料都要重新输入了!请高手指点!最好有相关实例!或者有其他更好的方法实现这个功能!

解决方案 »

  1.   

    可以实现这个功能,我提供你一个简单的思路:
    <form>
    <iframe .....>
    </form>
    你将你的要获取路径的文本框放在了另一个form中,通过的单击文件上传按钮,给form中的文本框复制,这个可以通过调用自己写的JS方法来完成!试一下,加油
      

  2.   

    iframe上传后里面有个获得文件路径的文本框会有上传后的路径显示出来,我就是不会将iframe中的文本框传递到main.php的文本框中来
      

  3.   

    用AJAX可以实现,点击按钮上传,在后台获取文件上传后的路径,parent.document.getElementById("文本框id").innerHTML=后台返回的路径。
      

  4.   

    问一下LZ,在main.php文本框中获得文件上传后的路径,这里的路径是上传后的文件保存的路径吧?
    move_uploaded_file()里面的第二个参数就是你保存的路径啊,这样传值就简单多了啊
    <input type=hidden id=hidValue value=<?php echo $path?>>
    提交文件触发事件:
    fucntion ***()
    {
      parent.document.getElementById("接受值的文本框的ID").value=document.getElementById.hidValue;
    }
      

  5.   

    我本来在iframe中有个获取上传后地址的文本框,上传成功后才显示,现在最好上传成功后直接传到main.php的文本框中,ajax代码我不太会用,麻烦说详细点
      

  6.   

    在google搜一下"ajax实例",很多。
      

  7.   

    upload.php<?php
    $uptypes=array('image/jpg',  //上传文件类型列表
     'image/jpeg',
     'image/png',
     'image/pjpeg',
     'image/gif',
     'image/bmp',
     'application/msword',
     'application/octet-stream',
     'application/x-zip-compressed');$max_file_size=20000000;   //上传文件大小限制, 单位BYTE
    $path_parts=pathinfo($_SERVER['PHP_SELF']); //取得当前路径
    $destination_folder="../file/"; //上传文件路径
    ?>
    <html>
    <head>
    <title>文件上传</title>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    </head>
    <body leftmargin='0' topmargin='0' marginwidth='0' marginheight='0' scroll='no'>
        <table border="0" width="300" id="table" cellspacing=0>
        <form enctype="multipart/form-data" method="post" name="upform">
          <tr>
            <td width="100%">
              <input style="width:208;border:1 solid #9a9999; font-size:9pt; background-color:#ffffff; height:18" size="17" name=upfile type=file 
    onchange="javascript:FileChange(this.value);">
              <input type="submit" value="上传" style="width:60;border:1 solid #9a9999; font-size:9pt; background-color:#ffffff; height:18" size="17"></td>
          </tr>
          </form>
        </table>
      <?php
    if ($_SERVER['REQUEST_METHOD'] == 'POST')
    {
    if (!is_uploaded_file($_FILES["upfile"][tmp_name]))
    //是否存在文件
    {
    echo "<font color='red'>文件不存在!</font>";
    exit;
    } $file = $_FILES["upfile"];
     if($max_file_size < $file["size"])
     //检查文件大小
     {
     echo "<font color='red'>文件太大!</font>";
     exit;
      }if(!in_array($file["type"], $uptypes))
    //检查文件类型
    {
     echo "<font color='red'>不能上传此类型文件!</font>";
     exit;
    }if(!file_exists($destination_folder))
    mkdir($destination_folder);$filename=$file["tmp_name"];
    $image_size = getimagesize($filename);
    $pinfo=pathinfo($file["name"]);
    $ftype=$pinfo[extension];
    $destination = $destination_folder.time().".".$ftype;
    if (file_exists($destination) && $overwrite != true)
    {
         echo "<font color='red'>同名文件已经存在了!</a>";
         exit;
      } if(!move_uploaded_file ($filename, $destination))
     {
       echo "<font color='red'>移动文件出错!</a>";
         exit;
      }$pinfo=pathinfo($destination);
    $fname=$pinfo[basename];
    #上传成功后的地址
    echo "<table width=\"150\" cellspacing=\"0\" cellpadding=\"5\" border=\"0\" class=\"table_decoration\" align=\"left\"><tr><td><div id=\"site\"><form name=\"frm\"><table border=\"0\"><tr><td valign=\"top\"><font color=\"#FF0000\" size=\"2px\">上传成功!</font></td></tr><tr><td><input type=\"text\" style=font-size=9pt;color:blue size=\"30\" value=\"".$destination_folder.$fname."\" readonly name=\"upname\" id=\"upname\"></td></tr></table></div></td></tr></form></table>";
    if($water==1)
    {
    $iinfo=getimagesize($destination,$iinfo);
    $nimage=imagecreatetruecolor($image_size[0],$image_size[1]);
    $white=imagecolorallocate($nimage,255,255,255);
    $black=imagecolorallocate($nimage,0,0,0);
    $red=imagecolorallocate($nimage,255,0,0);
    imagefill($nimage,0,0,$white);
    switch ($iinfo[2])
    {
     case 1:
     $simage =imagecreatefromgif($destination);
     break;
     case 2:
     $simage =imagecreatefromjpeg($destination);
     break;
     case 3:
     $simage =imagecreatefrompng($destination);
     break;
     case 6:
     $simage =imagecreatefromwbmp($destination);
     break;
     default:
     die("<font color='red'>不能上传此类型文件!</a>");
     exit;
    }imagecopy($nimage,$simage,0,0,0,0,$image_size[0],$image_size[1]);
    imagefilledrectangle($nimage,1,$image_size[1]-15,80,$image_size[1],$white);switch($watertype)
    {
     case 1:  //加水印字符串
     imagestring($nimage,2,3,$image_size[1]-15,$waterstring,$black);
     break;
     case 2:  //加水印图片
     $simage1 =imagecreatefromgif("xplore.gif");
     imagecopy($nimage,$simage1,0,0,0,0,85,15);
     imagedestroy($simage1);
     break;
    }switch ($iinfo[2])
    {
     case 1:
     //imagegif($nimage, $destination);
     imagejpeg($nimage, $destination);
     break;
     case 2:
     imagejpeg($nimage, $destination);
     break;
     case 3:
     imagepng($nimage, $destination);
     break;
     case 6:
     imagewbmp($nimage, $destination);
     //imagejpeg($nimage, $destination);
     break;
    }//覆盖原上传文件
    imagedestroy($nimage);
    imagedestroy($simage);
    }
    }
    ?>
    </body>
    </html>
    main.php<table border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#CCCCCC"  class="inputtable" style="padding:0px;">
      <tr> 
        <td bgcolor="#EBEBEB" class="tishi">&nbsp;发布通知(<font color="#FF0000">*必填写</font>)</td>
      </tr>
      <tr> 
        <td bgcolor="#FFFFFF" height="30" style="padding:0px;border-bottom:1px solid #C6CBEE;"> 
    <form name="myform" method="post"  onsubmit="return FormCheck();" style="padding:0px;margin:0px 0px 0px 0px;">
        <table width="100%" border="0" cellspacing="0" cellpadding="0" >
              <tr> 
                <td class="crm_td"><font color="#FF0000">*</font>标&nbsp;&nbsp;&nbsp;&nbsp;题:</td>
                <td class="crm_input"><input name="Title" type="text" id="Title" size="20" maxlength="30" class=sHistory></td>
              </tr>
              <tr> 
                <td width="15%"   class="crm_td"> 
                  <font color="#FF0000">*</font>发布区域:</td>
                <td width="45%" class="crm_input"><input name="TitleArea" type="text" id="TitleArea" size="20" maxlength="30" class=sHistory>
                </td>
                </tr>
              <tr> 
                <td class="crm_td">附&nbsp;&nbsp;&nbsp;&nbsp;件:</td>
                <td class="crm_input"><iframe src="upload.php" frameborder='0' scrolling='no' height="80" name="up" id="up"></iframe>
                <br />上传成功后的地址:<input type="text" name="FileName" id="FileName">
                </td>
              </tr>
              <tr> 
                <td class="crm_td"><font color="#FF0000">*</font>内&nbsp;&nbsp;&nbsp;&nbsp;容:</td>
                <td class="crm_input"><textarea name="Content" cols="60" rows="5"  id="Content" onkeyUp="textLimitCheck(this, 500);" class=sHistory></textarea>
                  <br>最多500汉字</td>
              </tr>
              <tr align="center"> 
                <td colspan="2"   class="crm_submit"> 
                  <input type="submit" name="Submit" class="submit" value=" 确 定 ">
                  &nbsp;&nbsp;&nbsp;&nbsp; <input type="reset" name="Submit2" class="submit" value=" 重 填 "></td>
              </tr>
            </table>
          </form></td>
      </tr>
    </table>
      

  8.   

    职位要求:
    1.熟悉PHP语言,能自己解决实际问题。
    2.能书写常用的SQL语句。
    3.熟悉HTML/Javascript/等WEB技术
    4.至少有一年以上的PHP工作经验
    5.工作积极主动,比较踏实,责任心强。符合以下条件者优先:
    在linux环境下能简单操作和配置一些常用服务。
    对cakephp或者symfony框架有丰富的开发经验(不做必须要求);工作地点:北京海淀区知春路紫金数码3#909
    薪水待遇:面议
    联系人:徐小姐
    邮箱:[email protected]
    公司网址:http://www.fp-star.com
    公司简介:  北京五极星信息系统技术有限公司成立于2005年7月。是一家综合软件产品服务提供商。公司位于中关村知春路紫金数码园,是拥有多个具有自主知识产权产品的高科技企业。
    除去自主软件产品研发以外,公司同时还提供对日软件开发服务。经过多年的积累,目前公司拥有一批优秀的软件工程师,能为客户提供从基本业务分析一直到系统详细设计、开发、测试、售后服务等一系列的优质服务。