problems using copy() and rename()

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • mantrid

    problems using copy() and rename()

    Im trying to move a file but am having luck
    my code is below. The temp and target paths are valid as they echo
    correctly. but I cant get the copy() function to work, or the rename()
    function

    $target_path = $targetdir . basename($uploa dedfile["name"][$x]);
    $temp_path = $tempdir. basename($uploa dedfile["name"][$x]);

    echo "Target - ".$target_path. " Temp - ".$temp_path."< br>";

    copy($temp_path , $target_path);

    has any one experienced this problem?

    Ian





  • peter

    #2
    Re: problems using copy() and rename()


    "mantrid" <ian.dandav@vir gin.netwrote in message
    news:%7o_g.143$ 76.75@newsfe5-win.ntli.net...
    Im trying to move a file but am having luck
    my code is below. The temp and target paths are valid as they echo
    correctly. but I cant get the copy() function to work, or the rename()
    function
    >
    $target_path = $targetdir . basename($uploa dedfile["name"][$x]);
    $temp_path = $tempdir. basename($uploa dedfile["name"][$x]);
    >
    echo "Target - ".$target_path. " Temp - ".$temp_path."< br>";
    >
    copy($temp_path , $target_path);
    >
    has any one experienced this problem?
    >
    are you receiving any error if so what is it? Also if it is as it looks and
    is a file that has been uploaded then why not use the move_uploaded_f ile()
    function.


    Comment

    • mantrid

      #3
      Re: problems using copy() and rename()


      "peter" <submit@flexiwe bhost.comwrote in message
      news:ehd81o$cu8 $1@aioe.org...
      >
      "mantrid" <ian.dandav@vir gin.netwrote in message
      news:%7o_g.143$ 76.75@newsfe5-win.ntli.net...
      Im trying to move a file but am having luck
      my code is below. The temp and target paths are valid as they echo
      correctly. but I cant get the copy() function to work, or the rename()
      function

      $target_path = $targetdir . basename($uploa dedfile["name"][$x]);
      $temp_path = $tempdir. basename($uploa dedfile["name"][$x]);

      echo "Target - ".$target_path. " Temp - ".$temp_path."< br>";

      copy($temp_path , $target_path);

      has any one experienced this problem?
      >

      are you receiving any error if so what is it? Also if it is as it looks
      and
      is a file that has been uploaded then why not use the move_uploaded_f ile()
      function.
      >
      >
      I tried with the move_uploaded_f ile() originally but this didnt work
      either. I thought maybe it only works initially with $_FILES as I understand
      it checks that a file has been uploaded and returns negative if it cant find
      one.
      Ther is no error message it appears to work as my success message is
      displayed but the file is not there


      Comment

      • mantrid

        #4
        Re: problems using copy() and rename()


        "mantrid" <ian.dandav@vir gin.netwrote in message
        news:eUp_g.4206 0$6C2.34098@new sfe6-gui.ntli.net...
        >
        "peter" <submit@flexiwe bhost.comwrote in message
        news:ehd81o$cu8 $1@aioe.org...

        "mantrid" <ian.dandav@vir gin.netwrote in message
        news:%7o_g.143$ 76.75@newsfe5-win.ntli.net...
        Im trying to move a file but am having luck
        my code is below. The temp and target paths are valid as they echo
        correctly. but I cant get the copy() function to work, or the rename()
        function
        >
        $target_path = $targetdir . basename($uploa dedfile["name"][$x]);
        $temp_path = $tempdir. basename($uploa dedfile["name"][$x]);
        >
        echo "Target - ".$target_path. " Temp - ".$temp_path."< br>";
        >
        copy($temp_path , $target_path);
        >
        has any one experienced this problem?
        >
        >
        >
        >
        are you receiving any error if so what is it? Also if it is as it looks
        and
        is a file that has been uploaded then why not use the
        move_uploaded_f ile()
        function.
        >
        I tried with the move_uploaded_f ile() originally but this didnt work
        either. I thought maybe it only works initially with $_FILES as I
        understand
        it checks that a file has been uploaded and returns negative if it cant
        find
        one.
        Ther is no error message it appears to work as my success message is
        displayed but the file is not there
        >
        >
        Here is the full code. as you can see ive commented out much of it to try
        and narrow down the problem. Ive used an echo to check that the session
        variables are valid. but the file just will not move

        $userid=$_SESSI ON[userid];
        $delquest=$_SES SION[delquest];
        $archivequest=$ _SESSION[archivequest];
        $changedquests= $_SESSION[changed];
        $questids=$_SES SION[questids];
        $imagechanged=$ _SESSION[imagechanged];
        $delimage=$_SES SION['delimage'];
        $msg=$_SESSION['msg'];
        $uploadedfile=$ _SESSION['uploadedfile'];
        $imagepath=$_SE SSION['imagepath'];
        $questuserid=$_ SESSION[questuserid];
        $imagequestinde x=$_SESSION[imagequestindex];

        if(count($image changed)>0){
        $targetdir = "pupilteste r/";
        $tempdir= "temp/";
        $allowed_file_t ypes = "(jpg|jpeg|gif| bmp|png)";
        for ($x = 0; $x < count($imageque stindex); $x++){
        if(!empty($uplo adedfile["name"][$x])){

        $target_path = $targetdir . basename($uploa dedfile["name"][$x]);
        $temp_path = $tempdir. basename($uploa dedfile["name"][$x]);
        $imagefile=$ima gepath[$x];
        echo "Userid - ".$questuse rid[$x]." Target - ".$target_path. " Temp -
        ".$temp_pat h." To replace - ".$imagefile."< br>";
        copy("$temp_pat h", "$target_path") ;
        //if($uploadedfil e["size"][$x] < 35841) {
        //if(preg_match("/\." . $allowed_file_t ypes . "$/i",
        $uploadedfile["name"][$x])) {
        if(file_exists( $target_path)){
        //if($questuserid[$x]=$userid){
        $sql2 = "UPDATE questions SET
        ImagePath='".$u ploadedfile["name"][$x]."' WHERE ImagePath='".$i magefile."'";
        $addquest = mysql_query($sq l2) or $msg.="<br><spa n
        class='RedWarni ng'>Problem adding image name ".$uploaded file['name'][$x]."
        to database: " . mysql_error()." </span>";

        if(file_exists( $targetdir.$ima gefile)){unlink ($targetdir.$im agefile);}
        //$msg.="<br><spa n class='greenbod y'>Link formed to your existing
        file by the name of ".$uploaded file["name"][$x].".</span>";
        //}else{
        //$msg.="<br><spa n class='RedWarni ng'>A image by the name of
        ".$uploaded file["name"][$x]." already exists for another users question.
        Please rename it and try again.</span>";
        //}
        }else{
        rename($temp_pa th, $target_path);
        //if(move_uploade d_file($temp_pa th, $target_path)){
        //$msg.="<br><spa n class='greenbod y'>Uploaded the image
        ".$uploaded file["name"][$x]." (" .$uploadedfile["type"][$x]. ",
        ".ceil($uploade dfile["size"][$x] / 1024) . " Kb).</span>";
        //if($uploadedfil e['name'][$x]!==''){
        $sql2 = "UPDATE questions SET
        ImagePath='".$u ploadedfile["name"][$x]."' WHERE ImagePath='".$i magefile."'";
        $addquest = mysql_query($sq l2) or $msg.="<br><spa n
        class='RedWarni ng'>Problem adding image name ".$uploaded file['name'][$x]."
        to database: " . mysql_error()." </span>";

        if(file_exists( $targetdir.$ima gefile)){unlink ($targetdir.$im agefile);}
        //}
        //}else{
        //$msg.="<br><spa n class='Red Warning'>Error uploading image -
        ".$uploaded file['name'][$x].$uploadedfile['error'][$x]."</span>";
        //}
        }
        //}else{
        //$msg.="<br><spa n
        class='RedWarni ng'>".$uploaded file['name'][$x].$uploadedfile['error'][$x]."
        not uploaded. Not a valid image file.</span>";
        //}
        //}else{
        //$msg.="<br><spa n class='RedWarni ng'>".$uploaded file['name'][$x]." is
        greater than 35Kb.</span>";
        //}
        }
        }
        //$_SESSION['msg']=$msg;
        //echo("<br><br>< div align='center'> ".$msg."<br><br ><a
        href='usersques tions.php' class='BodyLink '>Return</a></div>");
        }



        Comment

        • mantrid

          #5
          Re: problems using copy() and rename()


          "mantrid" <ian.dandav@vir gin.netwrote in message
          news:kZp_g.4206 3$6C2.24358@new sfe6-gui.ntli.net...
          >
          "mantrid" <ian.dandav@vir gin.netwrote in message
          news:eUp_g.4206 0$6C2.34098@new sfe6-gui.ntli.net...

          "peter" <submit@flexiwe bhost.comwrote in message
          news:ehd81o$cu8 $1@aioe.org...
          >
          "mantrid" <ian.dandav@vir gin.netwrote in message
          news:%7o_g.143$ 76.75@newsfe5-win.ntli.net...
          Im trying to move a file but am having luck
          my code is below. The temp and target paths are valid as they echo
          correctly. but I cant get the copy() function to work, or the
          rename()
          function

          $target_path = $targetdir . basename($uploa dedfile["name"][$x]);
          $temp_path = $tempdir. basename($uploa dedfile["name"][$x]);

          echo "Target - ".$target_path. " Temp - ".$temp_path."< br>";

          copy($temp_path , $target_path);

          has any one experienced this problem?

          >

          are you receiving any error if so what is it? Also if it is as it
          looks
          and
          is a file that has been uploaded then why not use the
          move_uploaded_f ile()
          function.
          >
          >
          I tried with the move_uploaded_f ile() originally but this didnt work
          either. I thought maybe it only works initially with $_FILES as I
          understand
          it checks that a file has been uploaded and returns negative if it cant
          find
          one.
          Ther is no error message it appears to work as my success message is
          displayed but the file is not there
          >
          Here is the full code. as you can see ive commented out much of it to try
          and narrow down the problem. Ive used an echo to check that the session
          variables are valid. but the file just will not move
          >
          $userid=$_SESSI ON[userid];
          $delquest=$_SES SION[delquest];
          $archivequest=$ _SESSION[archivequest];
          $changedquests= $_SESSION[changed];
          $questids=$_SES SION[questids];
          $imagechanged=$ _SESSION[imagechanged];
          $delimage=$_SES SION['delimage'];
          $msg=$_SESSION['msg'];
          $uploadedfile=$ _SESSION['uploadedfile'];
          $imagepath=$_SE SSION['imagepath'];
          $questuserid=$_ SESSION[questuserid];
          $imagequestinde x=$_SESSION[imagequestindex];
          >
          if(count($image changed)>0){
          $targetdir = "pupilteste r/";
          $tempdir= "temp/";
          $allowed_file_t ypes = "(jpg|jpeg|gif| bmp|png)";
          for ($x = 0; $x < count($imageque stindex); $x++){
          if(!empty($uplo adedfile["name"][$x])){
          >
          $target_path = $targetdir . basename($uploa dedfile["name"][$x]);
          $temp_path = $tempdir. basename($uploa dedfile["name"][$x]);
          $imagefile=$ima gepath[$x];
          echo "Userid - ".$questuse rid[$x]." Target - ".$target_path. "
          Temp -
          ".$temp_pat h." To replace - ".$imagefile."< br>";
          copy("$temp_pat h", "$target_path") ;
          //if($uploadedfil e["size"][$x] < 35841) {
          //if(preg_match("/\." . $allowed_file_t ypes . "$/i",
          $uploadedfile["name"][$x])) {
          if(file_exists( $target_path)){
          //if($questuserid[$x]=$userid){
          $sql2 = "UPDATE questions SET
          ImagePath='".$u ploadedfile["name"][$x]."' WHERE
          ImagePath='".$i magefile."'";
          $addquest = mysql_query($sq l2) or $msg.="<br><spa n
          class='RedWarni ng'>Problem adding image name ".$uploaded file['name'][$x]."
          to database: " . mysql_error()." </span>";
          >
          if(file_exists( $targetdir.$ima gefile)){unlink ($targetdir.$im agefile);}
          //$msg.="<br><spa n class='greenbod y'>Link formed to your existing
          file by the name of ".$uploaded file["name"][$x].".</span>";
          //}else{
          //$msg.="<br><spa n class='RedWarni ng'>A image by the name of
          ".$uploaded file["name"][$x]." already exists for another users question.
          Please rename it and try again.</span>";
          //}
          }else{
          rename($temp_pa th, $target_path);
          //if(move_uploade d_file($temp_pa th, $target_path)){
          //$msg.="<br><spa n class='greenbod y'>Uploaded the image
          ".$uploaded file["name"][$x]." (" .$uploadedfile["type"][$x]. ",
          ".ceil($uploade dfile["size"][$x] / 1024) . " Kb).</span>";
          //if($uploadedfil e['name'][$x]!==''){
          $sql2 = "UPDATE questions SET
          ImagePath='".$u ploadedfile["name"][$x]."' WHERE
          ImagePath='".$i magefile."'";
          $addquest = mysql_query($sq l2) or $msg.="<br><spa n
          class='RedWarni ng'>Problem adding image name ".$uploaded file['name'][$x]."
          to database: " . mysql_error()." </span>";
          >
          if(file_exists( $targetdir.$ima gefile)){unlink ($targetdir.$im agefile);}
          //}
          //}else{
          //$msg.="<br><spa n class='Red Warning'>Error uploading image -
          ".$uploaded file['name'][$x].$uploadedfile['error'][$x]."</span>";
          //}
          }
          //}else{
          //$msg.="<br><spa n
          >
          class='RedWarni ng'>".$uploaded file['name'][$x].$uploadedfile['error'][$x]."
          not uploaded. Not a valid image file.</span>";
          //}
          //}else{
          //$msg.="<br><spa n class='RedWarni ng'>".$uploaded file['name'][$x]."
          is
          greater than 35Kb.</span>";
          //}
          }
          }
          //$_SESSION['msg']=$msg;
          //echo("<br><br>< div align='center'> ".$msg."<br><br ><a
          href='usersques tions.php' class='BodyLink '>Return</a></div>");
          }
          >
          >
          >
          OK ive played around with it and have found the following

          THIS DOESNT WORK

          $targetdir = "pupilteste r/";
          $tempdir= "temp/";

          $target_path = $targetdir."Arm .jpg";
          $temp_path = $tempdir."Arm.j pg";
          rename($temp_pa th, $target_path);



          BUT THIS DOES

          $target_path = "pupilteste r/Arm.jpg";
          $temp_path = "temp/Arm.jpg";
          rename($temp_pa th, $target_path);

          I cant see it am I being completely thick and missing something obvious


          Comment

          • peter

            #6
            Re: problems using copy() and rename()

            OK ive played around with it and have found the following
            >
            THIS DOESNT WORK
            >
            $targetdir = "pupilteste r/";
            $tempdir= "temp/";
            >
            $target_path = $targetdir."Arm .jpg";
            $temp_path = $tempdir."Arm.j pg";
            rename($temp_pa th, $target_path);
            >
            >
            >
            BUT THIS DOES
            >
            $target_path = "pupilteste r/Arm.jpg";
            $temp_path = "temp/Arm.jpg";
            rename($temp_pa th, $target_path);
            >
            I cant see it am I being completely thick and missing something obvious
            >
            that is mighty strange because essentially they are the same thing. Have you
            tried using full path's instead of relative paths?


            Comment

            • peter

              #7
              Re: problems using copy() and rename()


              "peter" <submit@flexiwe bhost.comwrote in message
              news:ehde9o$lfs $1@aioe.org...
              >
              >OK ive played around with it and have found the following
              >>
              >THIS DOESNT WORK
              >>
              > $targetdir = "pupilteste r/";
              > $tempdir= "temp/";
              >>
              > $target_path = $targetdir."Arm .jpg";
              > $temp_path = $tempdir."Arm.j pg";
              > rename($temp_pa th, $target_path);
              >>
              >>
              >>
              >BUT THIS DOES
              >>
              > $target_path = "pupilteste r/Arm.jpg";
              > $temp_path = "temp/Arm.jpg";
              > rename($temp_pa th, $target_path);
              >>
              >I cant see it am I being completely thick and missing something obvious
              >>
              >
              that is mighty strange because essentially they are the same thing. Have
              you tried using full path's instead of relative paths?
              also just to further on my previous post.

              Is there a reason you are storing the paths in the session? just seems a
              strange thing to do. Are they changing depending on the user.

              Regarding not receiving an error ensure you have the following at the top of
              your script:-

              error_reporting (E_ALL);

              It is possible that the errors are being supressed for some reason (possibly
              the default error reporting level in the php.ini file set too low)


              Comment

              • mantrid

                #8
                Re: problems using copy() and rename()


                "peter" <submit@flexiwe bhost.comwrote in message
                news:ehdeli$lsh $1@aioe.org...
                >
                "peter" <submit@flexiwe bhost.comwrote in message
                news:ehde9o$lfs $1@aioe.org...
                OK ive played around with it and have found the following
                >
                THIS DOESNT WORK
                >
                $targetdir = "pupilteste r/";
                $tempdir= "temp/";
                >
                $target_path = $targetdir."Arm .jpg";
                $temp_path = $tempdir."Arm.j pg";
                rename($temp_pa th, $target_path);
                >
                >
                >
                BUT THIS DOES
                >
                $target_path = "pupilteste r/Arm.jpg";
                $temp_path = "temp/Arm.jpg";
                rename($temp_pa th, $target_path);
                >
                I cant see it am I being completely thick and missing something obvious
                >
                that is mighty strange because essentially they are the same thing. Have
                you tried using full path's instead of relative paths?
                >
                also just to further on my previous post.
                >
                Is there a reason you are storing the paths in the session? just seems a
                strange thing to do. Are they changing depending on the user.
                The paths are not used directly after the form they are created on is
                posted. A page detailing the changes to be made is shown first and only when
                the user clicks continue does the file with the rename function open Hence
                the use of sessions to carry everything forward.

                Regarding not receiving an error ensure you have the following at the top
                of
                your script:-
                >
                error_reporting (E_ALL);
                That has thrown up lots of notices, most of which are of the type:
                Notice: Use of undefined constant archivequest - assumed 'archivequest' in
                .......

                seems to be picking up all my variables ie in the above example
                $archivequest do you know how to clear these type of notices?
                It is possible that the errors are being supressed for some reason
                (possibly
                the default error reporting level in the php.ini file set too low)
                >
                It doesn't seem to affect other error messages. it is strange that it is
                only happening in this case.
                I have been doing some work on this page all day Ive just

                put
                $targetdir = "pupilteste r/";
                $tempdir= "temp/";

                back in. And now it works. Dont know what I did but its ok now.



                Comment

                • peter

                  #9
                  Re: problems using copy() and rename()

                  That has thrown up lots of notices, most of which are of the type:
                  Notice: Use of undefined constant archivequest - assumed 'archivequest' in
                  ......
                  >
                  seems to be picking up all my variables ie in the above example
                  $archivequest do you know how to clear these type of notices?
                  had a quick look over your code and the reason for those errors are as
                  follows:-

                  you have lines such as:-

                  $archivequest=$ _SESSION[archivequest];

                  it should be:-

                  $archivequest=$ _SESSION['archivequest'];

                  because you do not have the quotes around them it is assuming they are
                  constants but as no constant is there it is using it as a string. This will
                  not always be the desired effect. Try and work with the error reporting
                  level that I already mentioned and it will cut down on alot of possible bugs
                  in your code.


                  Comment

                  • mantrid

                    #10
                    Re: problems using copy() and rename()


                    "peter" <submit@flexiwe bhost.comwrote in message
                    news:ehe92r$ps7 $1@aioe.org...
                    >
                    That has thrown up lots of notices, most of which are of the type:
                    Notice: Use of undefined constant archivequest - assumed 'archivequest'
                    in
                    ......

                    seems to be picking up all my variables ie in the above example
                    $archivequest do you know how to clear these type of notices?
                    >
                    had a quick look over your code and the reason for those errors are as
                    follows:-
                    >
                    you have lines such as:-
                    >
                    $archivequest=$ _SESSION[archivequest];
                    >
                    it should be:-
                    >
                    $archivequest=$ _SESSION['archivequest'];
                    >
                    because you do not have the quotes around them it is assuming they are
                    constants but as no constant is there it is using it as a string. This
                    will
                    not always be the desired effect. Try and work with the error reporting
                    level that I already mentioned and it will cut down on alot of possible
                    bugs
                    in your code.
                    >
                    >
                    That seems to have done it all except these ones

                    Notice: Undefined index: cancel in
                    /home/iddsoftw/public_html/questiondbase/questionupdate. php on line 11

                    Warning: Cannot modify header information - headers already sent by (output
                    started at /home/iddsoftw/public_html/questiondbase/questionupdate. php:11)
                    in /home/iddsoftw/public_html/questiondbase/questionupdate. php on line 17


                    refering to the top of my page (below)


                    <?php
                    session_start() ;
                    error_reporting (E_ALL); //show all errors

                    ini_set( "session.bug_co mpat_warn", "off" );

                    if(!isset($_SES SION['userid'])){
                    header("Locatio n: http://www.site.co.uk/forbidden.html" );
                    }

                    $cancel=$_POST['cancel'];
                    if(isset($cance l)){
                    header("Locatio n: http://www.site.co.uk/path/my.php");
                    }else{


                    header("Cache-control: private"); //IE 6 Fix
                    include("../include/idd.php");

                    ?>
                    <html>
                    <head>

                    <link href="../CSS/body.css" rel="stylesheet " type="text/css">
                    </head>
                    <body>


                    <?php
                    $userid=$_SESSI ON['userid'];
                    $delquest=$_SES SION['delquest'];
                    $archivequest=$ _SESSION['archivequest'];
                    $changedquests= $_SESSION['changed'];
                    $questids=$_SES SION['questids'];
                    $imagechanged=$ _SESSION['imagechanged'];
                    $delimage=$_SES SION['delimage'];
                    $msg=$_SESSION['msg'];
                    $uploadedfile=$ _SESSION['uploadedfile'];
                    $imagepath=$_SE SSION['imagepath'];
                    $questuserid=$_ SESSION['questuserid'];
                    $imagequestinde x=$_SESSION['imagequestinde x'];

                    $targetdir = "pupilteste r/";
                    $tempdir= "temp/";


                    CODE HERE

                    unset($_SESSION['delquest']);
                    unset($_SESSION['archivequest']);
                    unset($_SESSION['changed']);
                    unset($_SESSION['questids']);
                    unset($_SESSION['iseditable']);
                    unset($_SESSION['imagechanged']);
                    unset($_SESSION['uploadedfile']);
                    unset($_SESSION['cost']);
                    unset($_SESSION['question']);
                    unset($_SESSION['opta']);
                    unset($_SESSION['optb']);
                    unset($_SESSION['optc']);
                    unset($_SESSION['optd']);
                    unset($_SESSION['opte']);
                    unset($_SESSION['ans1']);
                    unset($_SESSION['ans2']);
                    unset($_SESSION['ans3']);
                    unset($_SESSION['ans4']);
                    unset($_SESSION['ans5']);
                    unset($_SESSION['ans6']);
                    unset($_SESSION['ans7']);
                    unset($_SESSION['ans8']);
                    unset($_SESSION['ans9']);
                    unset($_SESSION['ans10']);
                    unset($_SESSION['msg']);
                    unset($_SESSION['delimage']);
                    unset($_SESSION['imagepath']);
                    unset($_SESSION['imagequestinde x']);
                    ?>
                    </body>
                    </html>
                    <?php
                    }
                    ?>


                    Comment

                    • Jerry Stuckle

                      #11
                      Re: problems using copy() and rename()

                      mantrid wrote:
                      "peter" <submit@flexiwe bhost.comwrote in message
                      news:ehe92r$ps7 $1@aioe.org...
                      >
                      >>>That has thrown up lots of notices, most of which are of the type:
                      >>>Notice: Use of undefined constant archivequest - assumed 'archivequest'
                      >
                      in
                      >
                      >>>......
                      >>>
                      >>>seems to be picking up all my variables ie in the above example
                      >>>$archiveques t do you know how to clear these type of notices?
                      >>
                      >>had a quick look over your code and the reason for those errors are as
                      >>follows:-
                      >>
                      >>you have lines such as:-
                      >>
                      >>$archivequest =$_SESSION[archivequest];
                      >>
                      >>it should be:-
                      >>
                      >>$archivequest =$_SESSION['archivequest'];
                      >>
                      >>because you do not have the quotes around them it is assuming they are
                      >>constants but as no constant is there it is using it as a string. This
                      >
                      will
                      >
                      >>not always be the desired effect. Try and work with the error reporting
                      >>level that I already mentioned and it will cut down on alot of possible
                      >
                      bugs
                      >
                      >>in your code.
                      >>
                      >>
                      >
                      >
                      That seems to have done it all except these ones
                      >
                      Notice: Undefined index: cancel in
                      /home/iddsoftw/public_html/questiondbase/questionupdate. php on line 11
                      >
                      Warning: Cannot modify header information - headers already sent by (output
                      started at /home/iddsoftw/public_html/questiondbase/questionupdate. php:11)
                      in /home/iddsoftw/public_html/questiondbase/questionupdate. php on line 17
                      >
                      >
                      refering to the top of my page (below)
                      >
                      >
                      <?php
                      session_start() ;
                      error_reporting (E_ALL); //show all errors
                      >
                      ini_set( "session.bug_co mpat_warn", "off" );
                      >
                      if(!isset($_SES SION['userid'])){
                      header("Locatio n: http://www.site.co.uk/forbidden.html" );
                      }
                      >
                      $cancel=$_POST['cancel'];
                      if(isset($cance l)){
                      header("Locatio n: http://www.site.co.uk/path/my.php");
                      }else{
                      <snip>

                      It's saying $_POST['cancel'] isn't set, so the statement

                      $cancel=$_POST['cancel'];

                      is referencing a key ('cancel') which doesn't exist.

                      It should be something like:

                      if ($isset($_POST['cancel']) {
                      header("Locatio n: http://www.site.co.uk/path/my.php");
                      }
                      else {
                      ....

                      The "headers already sent" error error is because of the first error
                      message.



                      --
                      =============== ===
                      Remove the "x" from my email address
                      Jerry Stuckle
                      JDS Computer Training Corp.
                      jstucklex@attgl obal.net
                      =============== ===

                      Comment

                      • mantrid

                        #12
                        Re: problems using copy() and rename()

                        Thanks thats solved it.
                        I read somewhere you should assign posted info to variables at the top of
                        the script so that it will make managing the code easier. Hence my
                        $cancel=$_POST['cancel'];
                        is this not the case?

                        Ian

                        "Jerry Stuckle" <jstucklex@attg lobal.netwrote in message
                        news:8padnZI6cL YiTKfYnZ2dnUVZ_ sidnZ2d@comcast .com...
                        mantrid wrote:
                        "peter" <submit@flexiwe bhost.comwrote in message
                        news:ehe92r$ps7 $1@aioe.org...
                        >>That has thrown up lots of notices, most of which are of the type:
                        >>Notice: Use of undefined constant archivequest - assumed 'archivequest'
                        in
                        >>......
                        >>
                        >>seems to be picking up all my variables ie in the above example
                        >>$archiveque st do you know how to clear these type of notices?
                        >
                        >had a quick look over your code and the reason for those errors are as
                        >follows:-
                        >
                        >you have lines such as:-
                        >
                        >$archivequest= $_SESSION[archivequest];
                        >
                        >it should be:-
                        >
                        >$archivequest= $_SESSION['archivequest'];
                        >
                        >because you do not have the quotes around them it is assuming they are
                        >constants but as no constant is there it is using it as a string. This
                        will
                        >not always be the desired effect. Try and work with the error reporting
                        >level that I already mentioned and it will cut down on alot of possible
                        bugs
                        >in your code.
                        >
                        >

                        That seems to have done it all except these ones

                        Notice: Undefined index: cancel in
                        /home/iddsoftw/public_html/questiondbase/questionupdate. php on line 11

                        Warning: Cannot modify header information - headers already sent by
                        (output
                        started at
                        /home/iddsoftw/public_html/questiondbase/questionupdate. php:11)
                        in /home/iddsoftw/public_html/questiondbase/questionupdate. php on line
                        17


                        refering to the top of my page (below)


                        <?php
                        session_start() ;
                        error_reporting (E_ALL); //show all errors

                        ini_set( "session.bug_co mpat_warn", "off" );

                        if(!isset($_SES SION['userid'])){
                        header("Locatio n: http://www.site.co.uk/forbidden.html" );
                        }

                        $cancel=$_POST['cancel'];
                        if(isset($cance l)){
                        header("Locatio n: http://www.site.co.uk/path/my.php");
                        }else{
                        <snip>
                        >
                        It's saying $_POST['cancel'] isn't set, so the statement
                        >
                        $cancel=$_POST['cancel'];
                        >
                        is referencing a key ('cancel') which doesn't exist.
                        >
                        It should be something like:
                        >
                        if ($isset($_POST['cancel']) {
                        header("Locatio n: http://www.site.co.uk/path/my.php");
                        }
                        else {
                        ...
                        >
                        The "headers already sent" error error is because of the first error
                        message.
                        >
                        >
                        >
                        --
                        =============== ===
                        Remove the "x" from my email address
                        Jerry Stuckle
                        JDS Computer Training Corp.
                        jstucklex@attgl obal.net
                        =============== ===

                        Comment

                        • Jerry Stuckle

                          #13
                          Re: problems using copy() and rename()

                          mantrid wrote:
                          "Jerry Stuckle" <jstucklex@attg lobal.netwrote in message
                          news:8padnZI6cL YiTKfYnZ2dnUVZ_ sidnZ2d@comcast .com...
                          >
                          >>mantrid wrote:
                          >>
                          >>>"peter" <submit@flexiwe bhost.comwrote in message
                          >>>news:ehe92r$ ps7$1@aioe.org. ..
                          >>>
                          >>>
                          >>>>>That has thrown up lots of notices, most of which are of the type:
                          >>>>>Notice: Use of undefined constant archivequest - assumed 'archivequest'
                          >>>
                          >>>in
                          >>>
                          >>>
                          >>>>>......
                          >>>>>
                          >>>>>seems to be picking up all my variables ie in the above example
                          >>>>>$archivequ est do you know how to clear these type of notices?
                          >>>>
                          >>>>had a quick look over your code and the reason for those errors are as
                          >>>>follows:-
                          >>>>
                          >>>>you have lines such as:-
                          >>>>
                          >>>>$archiveque st=$_SESSION[archivequest];
                          >>>>
                          >>>>it should be:-
                          >>>>
                          >>>>$archiveque st=$_SESSION['archivequest'];
                          >>>>
                          >>>>because you do not have the quotes around them it is assuming they are
                          >>>>constants but as no constant is there it is using it as a string. This
                          >>>
                          >>>will
                          >>>
                          >>>
                          >>>>not always be the desired effect. Try and work with the error reporting
                          >>>>level that I already mentioned and it will cut down on alot of possible
                          >>>
                          >>>bugs
                          >>>
                          >>>
                          >>>>in your code.
                          >>>>
                          >>>>
                          >>>
                          >>>
                          >>>That seems to have done it all except these ones
                          >>>
                          >>>Notice: Undefined index: cancel in
                          >>>/home/iddsoftw/public_html/questiondbase/questionupdate. php on line 11
                          >>>
                          >>>Warning: Cannot modify header information - headers already sent by
                          >
                          (output
                          >
                          >>>started at
                          >
                          /home/iddsoftw/public_html/questiondbase/questionupdate. php:11)
                          >
                          >>>in /home/iddsoftw/public_html/questiondbase/questionupdate. php on line
                          >
                          17
                          >
                          >>>
                          >>>refering to the top of my page (below)
                          >>>
                          >>>
                          >>><?php
                          >>>session_star t();
                          >>>error_report ing(E_ALL); //show all errors
                          >>>
                          >>>ini_set( "session.bug_co mpat_warn", "off" );
                          >>>
                          >>>if(!isset($_ SESSION['userid'])){
                          >>>header("Loca tion: http://www.site.co.uk/forbidden.html" );
                          >>>}
                          >>>
                          >>>$cancel=$_PO ST['cancel'];
                          >>>if(isset($ca ncel)){
                          >>header("Locat ion: http://www.site.co.uk/path/my.php");
                          >>>}else{
                          >>
                          >><snip>
                          >>
                          >>It's saying $_POST['cancel'] isn't set, so the statement
                          >>
                          > $cancel=$_POST['cancel'];
                          >>
                          >>is referencing a key ('cancel') which doesn't exist.
                          >>
                          >>It should be something like:
                          >>
                          > if ($isset($_POST['cancel']) {
                          > header("Locatio n: http://www.site.co.uk/path/my.php");
                          > }
                          > else {
                          >>...
                          >>
                          >>The "headers already sent" error error is because of the first error
                          >>message.
                          >>
                          >>
                          Thanks thats solved it.
                          I read somewhere you should assign posted info to variables at the top of
                          the script so that it will make managing the code easier. Hence my
                          $cancel=$_POST['cancel'];
                          is this not the case?
                          >
                          Ian
                          >
                          (Top posting fixed)

                          Yes, it's often good to do it that way. But that's only 1/2 of it. You
                          must also ensure that the variable is set before you try to assign it!

                          If $_POST['cancel'] is not set, you get just the error you saw - because
                          you didn't have a button/checkbox/field/whatever named 'cancel' passed
                          from the browser.

                          P.S. Please don't top post. Thanks.


                          --
                          =============== ===
                          Remove the "x" from my email address
                          Jerry Stuckle
                          JDS Computer Training Corp.
                          jstucklex@attgl obal.net
                          =============== ===

                          Comment

                          Working...