problems

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

    #1

    problems

    Hi guys,
    On my site, the members can upload photos to a selected gallery, the photos
    will go into the correct folder depending what gallery they click.

    This all works ok, accept wen it causes an error, like the file exists or
    not enough data has been entered. It is then redirected to the addphotos
    page, but this time it loses which folder it should go into.

    addphotos2.php

    $table=$_GET[gal];
    $folder=$_GET[folder];
    echo $error; ?>
    <form action="connect photos.php" method="post"
    enctype="multip art/form-data">
    File:<br>
    <input type="file" name="imagefile " size="30"><br>
    Title:<br>
    <input type="text" name="title" size="50" maxlength="100" ><br>
    Comment:<br>
    <input type="text" name="comment" size="50" maxlength="200" ><br>
    <input type="hidden" name="table" value="<?php echo $table ?>">
    <input type="hidden" name="folder" value="<?php echo $folder ?>">
    <p>
    <input type="submit" value="Add Photo To <?php echo $folder?>"
    name="submit"> Please click only once, this may take a while.
    </form>

    connectphotos.p hp

    if
    (file_exists("/usr/local/psa/home/vhosts/x-tractband.co.uk/httpdocs/x-tract/
    photos/".$folder."/".$_FILES['imagefile']['name']))
    {
    $error= "<font face=\"Arial\" color=\"Yellow\ "><strong>F ile with name
    (".$_FILES["imagefile"]["name"] .") already exists</strong></font><br> ";

    include 'addphoto2.php' ;
    }

    how do i get the data sent by the form in the 1st place, to see be available
    when the error occurs.

    Hope fully you understand what i mean.

    Thanks

    --
    Kathryn (Fire Juggler)




  • Peter van Schie

    #2
    Re: problems

    That's because you use the GET variable 'folder' to set the selected
    folder in your addphotos2.php script:

    $folder=$_GET[folder];

    and

    <input type="hidden" name="folder" value="<?php echo $folder ?>">

    The connectphotos.p hp doesn't send a querystring to the addphotos2.php
    script, hence $_GET[folder] will be null.

    To store the value of $_GET[folder] you could use a session-var for
    instance, so it'll still be available after an error occured.

    HTH.

    --


    Comment

    • Fire Juggler

      #3
      Re: problems

      How would i use session-var?
      Thanks

      --
      Kathryn (Fire Juggler)



      "Peter van Schie" <vanschie.peter @gmail.com> wrote in message
      news:1121071688 .068453.183610@ o13g2000cwo.goo glegroups.com.. .[color=blue]
      > That's because you use the GET variable 'folder' to set the selected
      > folder in your addphotos2.php script:
      >
      > $folder=$_GET[folder];
      >
      > and
      >
      > <input type="hidden" name="folder" value="<?php echo $folder ?>">
      >
      > The connectphotos.p hp doesn't send a querystring to the addphotos2.php
      > script, hence $_GET[folder] will be null.
      >
      > To store the value of $_GET[folder] you could use a session-var for
      > instance, so it'll still be available after an error occured.
      >
      > HTH.
      >
      > --
      > http://www.phpforums.nl
      >[/color]


      Comment

      • Peter van Schie

        #4
        Re: problems

        Use session_start in each script you want to use your session
        variables:

        addphotos2.php
        <?php
        session_start() ;
        // check if $_GET['folder'] is set, if not use the session-var
        //
        if (isset($_GET['folder'])
        {
        $folder = $_GET['folder'];
        $_SESSION['folder'] = $folder;
        }
        else
        {
        $folder = $_SESSION['folder'];
        }

        .... other code ....
        ?>

        in connectphotos.p hp you should destroy the session when you don't need
        it anymore. That's probably when you don't have an error, so you get:

        <?php
        session_start() ;

        if
        (file_exists("/usr/local/psa/home/vhosts/x-tractband.co.uk/httpdocs/x-tract/photos/".$folder."/".$_FILES['imagefile']['name']))
        {
        $error= "<font face=\"Arial\" color=\"Yellow\ "><strong>F ile with
        name
        (".$_FILES["imagefile"]["name"] .") already exists</strong></font><br>
        ";

        include 'addphoto2.php' ;
        }
        else
        {
        session_destroy ();
        }
        ?>

        Also make sure to read the PHP manual page on sessions:


        --


        Comment

        • Fire Juggler

          #5
          Re: problems

          thanks
          when i use session_start() ; i'm getting errors saying that headers already
          sent.
          Y?
          Thanks

          --
          Kathryn (Fire Juggler)



          "Peter van Schie" <vanschie.peter @gmail.com> wrote in message
          news:1121072760 .877484.259090@ f14g2000cwb.goo glegroups.com.. .[color=blue]
          > Use session_start in each script you want to use your session
          > variables:
          >
          > addphotos2.php
          > <?php
          > session_start() ;
          > // check if $_GET['folder'] is set, if not use the session-var
          > //
          > if (isset($_GET['folder'])
          > {
          > $folder = $_GET['folder'];
          > $_SESSION['folder'] = $folder;
          > }
          > else
          > {
          > $folder = $_SESSION['folder'];
          > }
          >
          > .... other code ....
          > ?>
          >
          > in connectphotos.p hp you should destroy the session when you don't need
          > it anymore. That's probably when you don't have an error, so you get:
          >
          > <?php
          > session_start() ;
          >
          > if
          >[/color]
          (file_exists("/usr/local/psa/home/vhosts/x-tractband.co.uk/httpdocs/x-tract/
          photos/".$folder."/".$_FILES['imagefile']['name']))[color=blue]
          > {
          > $error= "<font face=\"Arial\" color=\"Yellow\ "><strong>F ile with
          > name
          > (".$_FILES["imagefile"]["name"] .") already exists</strong></font><br>
          > ";
          >
          > include 'addphoto2.php' ;
          > }
          > else
          > {
          > session_destroy ();
          > }
          > ?>
          >
          > Also make sure to read the PHP manual page on sessions:
          > http://nl3.php.net/session_start
          >
          > --
          > http://www.phpforums.nl
          >[/color]


          Comment

          • Peter van Schie

            #6
            Re: problems

            I think that's because of the
            include 'addphotos2.php '

            That way session_start gets called twice, first in connectphotos.p hp
            and then in addphotos2.php.

            You can circumvent that by moving the session_start() in
            connectphotos.p hp to the else block.

            Probably a cleaner way is to circumvent the include 'addphotos2.php ',
            by using:

            header("Locatio n: addphotos2.php" );

            Make sure you don't output *anything* before using the header call
            though.

            --


            Comment

            • Tim Van Wassenhove

              #7
              Re: problems

              On 2005-07-11, Peter van Schie <vanschie.peter @gmail.com> wrote:[color=blue]
              > I think that's because of the
              > include 'addphotos2.php '
              >
              > That way session_start gets called twice, first in connectphotos.p hp
              > and then in addphotos2.php.
              >
              > You can circumvent that by moving the session_start() in
              > connectphotos.p hp to the else block.[/color]


              if (!isset($_SESSI ON)) session_start() ;

              --
              Met vriendelijke groeten,
              Tim Van Wassenhove <http://timvw.madoka.be >

              Comment

              Working...