2014-10-20 64 views
0

我有这样的代码:我正在失去一个变量......在哪里?

<?php 
$id_sent = $_POST['id']; 
echo $id_sent; 
include ($_SERVER['DOCUMENT_ROOT']."/upload/upload_class.php"); 

$max_size      = 1024*250*500; 
$my_upload      = new file_upload; 
$my_upload->upload_dir   = $_SERVER['DOCUMENT_ROOT']."/uploads/"; 
$my_upload->extensions   = array(".pdf"); 
$my_upload->max_length_filename= 50; 
$my_upload->rename_file  = true; 
$my_upload->id_search   = $id_sent; 

if(isset($_POST['Submit'])) { 
    $my_upload->the_temp_file = $_FILES['upload']['tmp_name']; 
    $my_upload->the_file  = $_FILES['upload']['name']; 
    $my_upload->http_error  = $_FILES['upload']['error']; 

    if ($my_upload->upload()) { 
     mysql_query(sprintf("UPDATE psi_avize SET pdf = 'T' WHERE id = '%s'", $my_upload->id_search));?> 
     <table width="800" border="0"> 
      <tr> 
       <th width="167" rowspan="2" scope="col"><img src="images/figure_check_mark_celebrate_anim_md_wm.png" width="129" height="142"></th> 
       <th width="471" height="29" scope="col"><div align="left">Succes!</div></th> 
       <th width="148" scope="col">&nbsp;</th> 
      </tr> 
      <tr> 
       <td height="104">&nbsp;</td> 
       <td>&nbsp;</td> 
      </tr> 
     </table><?php 
     echo $my_upload->show_error_string(); 
    } 
} 
else {?> <strong>Insert file!</span></p> 
    </strong> 
    <table width="800" border="0"> 
    <tr> 
     <th width="167" rowspan="2" scope="col"><img src="images/document.png" width="150" height="152"></th> 
     <th width="471" height="29" scope="col"><div align="left"></div></th> 
     <th width="148" scope="col">&nbsp;</th> 
    </tr> 
    <tr> 
     <td height="104">Max = 5 MB.</td> 
     <td>&nbsp;</td> 
    </tr> 
    </table> 
    <p>&nbsp;</p> 
    Load file <form name="form1" action="<?php echo $_SERVER['PHP_SELF']; ?>" 
     enctype="multipart/form-data" method="post"> 
    <div align="center"> 
     <table width="100%" border="0" cellspacing="0" cellpadding="0"> 
      <tr> 
       <th width="11%" scope="col">&nbsp;</th> 
       <th width="26%" scope="col">&nbsp;</th> 
       <th width="51%" scope="col"><div align="left"> 
        <input type="hidden" name="MAX_FILE_SIZE" value="<?php echo $max_size; ?>" /> 
        <?php 
        echo $my_upload->create_file_field("upload", "Select file...", 25, false); ?></div></th> 
       <th width="12%" scope="col">&nbsp;</th> 
      </tr>  
      <tr> 
       <td>&nbsp;</td> 
       <td>&nbsp;</td> 
       <td><div align="left"> 
        <input name="Submit" type="submit" id="Submit" value="Upload" /> 
       </div></td> 
       <td>&nbsp;</td> 
      </tr> 
      </table> 
     </div> 
    </form> <?php } 
    ?> 

我的问题是,不知怎的,我松散的变量$ id_sent(它使用POST从其他网页发送),我不能够正确地使用查询ID。 当我回应第3行中的变量正在工作,但之后,我失去了该变量,我无法使用它。 谢谢!

+0

您没有名为'upload'的元素,但单独是输入类型'文件' – 2014-10-20 11:35:06

+0

@ Fred- ii错误的'$ my_upload-> create_file_field(...',而不是他以文件插入的形式缺少'id_sent' – 2014-10-20 11:37:56

+0

你应该从一个条件开始检查for是否被提交,比如.. if(isset $ _REQUEST ['id'])) – 2014-10-20 11:37:56

回答

2

看起来像你遇到的问题是,$id_sent来自另一页的帖子。这就是你能够首先正确回应它的原因。

加载当前页面后,单击当前页面表单的提交按钮,上一页中的POST值将被此页面上的POST值覆盖。

为了留住跨越此页上的信息的价值,以及,将其存储在一个隐藏字段,像这样

<input type ='hidden' name='id' value='<? php echo $id_sent; ?>'> 

所以在这里,在$id_sent围绕第一时间被设定为id从以前的价值页面文章。它也被设置为一个名为id的隐藏字段,在这个页面的表单中,然后将被考虑用于后续的表单提交。

+0

好的赶上,我推测这是由file_upload类处理(该操作没有告诉我们),但我期望这是正确的 – Steve 2014-10-20 11:45:42

+0

:)是的,谢谢。我会尝试! – 2014-10-20 11:48:36

+0

@Steve:谢谢 - 是的,尽管这个问题似乎没有说清楚,但我认为这可能是OP面临的问题。 – raidenace 2014-10-20 11:51:01