PHP file upload unexpected error - file too large?

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

    PHP file upload unexpected error - file too large?

    Hi,
    I have a short basic script to upload files. It works fine with small files,
    but with longer files it gets stuck.

    Here's the fragment, the input file is loaded in "$file" from an HTML form
    as usual.

    ....
    $img_str = fread(fopen($fi le, "r"), filesize($file) );
    $data = addslashes($img _str);
    // --------------------- up to here the execution is correct and fast (<1
    second)

    $sql="INSERT INTO $table (".
    " file_name,".
    " file_type,".
    " file_size,".
    " bin_data)".
    " VALUES (".
    " '$file_name',".
    " '$file_type',".
    " '$file_size',".
    " '$data')";
    // --------------------- it gets stuck
    here!!!!!!!!!!! !!!!!!!!!!!!!!! !!!!!!!!!!!!!!
    mysql_query($sq l) or die ("SQL error ..$sql");

    I have already set the php.ini variables as follows:
    memory_limit = 16M
    upload_max_file size = 6M

    I also checked the execution time to max_execution_t ime = 300 (even though I
    don't believe it should be necessary).
    The server is a P4 1.8 GHz, 256MB RAM

    Any suggestion? Am I missing out something?

    Thanks in advance,
    G.




  • Erwin Moller

    #2
    Re: PHP file upload unexpected error - file too large?

    Giulio Neri wrote:
    [color=blue]
    > Hi,
    > I have a short basic script to upload files. It works fine with small
    > files, but with longer files it gets stuck.
    >
    > Here's the fragment, the input file is loaded in "$file" from an HTML form
    > as usual.
    >
    > ...
    > $img_str = fread(fopen($fi le, "r"), filesize($file) );
    > $data = addslashes($img _str);
    > // --------------------- up to here the execution is correct and fast (<1
    > second)
    >
    > $sql="INSERT INTO $table (".
    > " file_name,".
    > " file_type,".
    > " file_size,".
    > " bin_data)".
    > " VALUES (".
    > " '$file_name',".
    > " '$file_type',".
    > " '$file_size',".
    > " '$data')";[/color]

    Are you aware that the query is very strange?
    Since you put ' instead of " around stringliterals, the SQL you produce
    might differ somewhat from what you expect.

    Always try:
    echo $sql;
    before posting to a newsgroup. :P

    You will have something like this:

    INSERT INTO sometable (file_name,file _type,file_size ,bin_data)
    VALUES
    ('$file_name', '$file_type' etc. etc)

    instead of the expected VALUES for the vars you use.

    Check your ' and "

    Regards,
    Erwin Moller
    [color=blue]
    > // --------------------- it gets stuck
    > here!!!!!!!!!!! !!!!!!!!!!!!!!! !!!!!!!!!!!!!!
    > mysql_query($sq l) or die ("SQL error ..$sql");
    >
    > I have already set the php.ini variables as follows:
    > memory_limit = 16M
    > upload_max_file size = 6M
    >
    > I also checked the execution time to max_execution_t ime = 300 (even though
    > I don't believe it should be necessary).
    > The server is a P4 1.8 GHz, 256MB RAM
    >
    > Any suggestion? Am I missing out something?
    >
    > Thanks in advance,
    > G.[/color]

    Comment

    • Giulio Neri

      #3
      Re: PHP file upload unexpected error - file too large?

      Erwin,
      the single quotation mark is required in the sql syntax to insert text /
      non-numeric values (mysql gives me an error otherwise).

      The real problem here is that the string concatenation fails and I cannot
      make it work...

      I also tried with something like:

      $sql="hello: $data";

      or

      $sql="hello: " . $data;

      and in both cases it fails (I believe it runs out of memory...).

      The file size is 4MB.


      Thanks for any additional advise.
      G.


      "Erwin Moller"
      <since_humans_r ead_this_I_am_s pammed_too_much @spamyourself.c om> wrote in
      message news:420774ff$0 $28990$e4fe514c @news.xs4all.nl ...[color=blue]
      > Giulio Neri wrote:
      >[color=green]
      > > Hi,
      > > I have a short basic script to upload files. It works fine with small
      > > files, but with longer files it gets stuck.
      > >
      > > Here's the fragment, the input file is loaded in "$file" from an HTML[/color][/color]
      form[color=blue][color=green]
      > > as usual.
      > >
      > > ...
      > > $img_str = fread(fopen($fi le, "r"), filesize($file) );
      > > $data = addslashes($img _str);
      > > // --------------------- up to here the execution is correct and fast[/color][/color]
      (<1[color=blue][color=green]
      > > second)
      > >
      > > $sql="INSERT INTO $table (".
      > > " file_name,".
      > > " file_type,".
      > > " file_size,".
      > > " bin_data)".
      > > " VALUES (".
      > > " '$file_name',".
      > > " '$file_type',".
      > > " '$file_size',".
      > > " '$data')";[/color]
      >
      > Are you aware that the query is very strange?
      > Since you put ' instead of " around stringliterals, the SQL you produce
      > might differ somewhat from what you expect.
      >
      > Always try:
      > echo $sql;
      > before posting to a newsgroup. :P
      >
      > You will have something like this:
      >
      > INSERT INTO sometable (file_name,file _type,file_size ,bin_data)
      > VALUES
      > ('$file_name', '$file_type' etc. etc)
      >
      > instead of the expected VALUES for the vars you use.
      >
      > Check your ' and "
      >
      > Regards,
      > Erwin Moller
      >[color=green]
      > > // --------------------- it gets stuck
      > > here!!!!!!!!!!! !!!!!!!!!!!!!!! !!!!!!!!!!!!!!
      > > mysql_query($sq l) or die ("SQL error ..$sql");
      > >
      > > I have already set the php.ini variables as follows:
      > > memory_limit = 16M
      > > upload_max_file size = 6M
      > >
      > > I also checked the execution time to max_execution_t ime = 300 (even[/color][/color]
      though[color=blue][color=green]
      > > I don't believe it should be necessary).
      > > The server is a P4 1.8 GHz, 256MB RAM
      > >
      > > Any suggestion? Am I missing out something?
      > >
      > > Thanks in advance,
      > > G.[/color]
      >[/color]


      Comment

      • Erwin Moller

        #4
        Re: PHP file upload unexpected error - file too large?

        Giulio Neri wrote:
        [color=blue]
        > Erwin,
        > the single quotation mark is required in the sql syntax to insert text /
        > non-numeric values (mysql gives me an error otherwise).
        >[/color]

        Right,

        But did you echo the SQL-string before executing?
        What came out?

        Regards,
        Erwin Moller
        [color=blue]
        > The real problem here is that the string concatenation fails and I cannot
        > make it work...[/color]

        that is why I advised you to check the ' and " in the first place.

        Try something like this.

        $sql="INSERT INTO $table (file_name,file _type,file_size ,bin_data)";
        $sql.= "VALUES ('".$file_name" ', '".$file_type." ' etc. etc

        Just use . to concatenate.

        Good luck.
        Let me/us know if you succeed.

        Regards,
        Erwin Moller

        [color=blue]
        >
        > I also tried with something like:
        >
        > $sql="hello: $data";
        >
        > or
        >
        > $sql="hello: " . $data;
        >
        > and in both cases it fails (I believe it runs out of memory...).
        >
        > The file size is 4MB.
        >
        >
        > Thanks for any additional advise.
        > G.
        >
        >
        > "Erwin Moller"
        > <since_humans_r ead_this_I_am_s pammed_too_much @spamyourself.c om> wrote in
        > message news:420774ff$0 $28990$e4fe514c @news.xs4all.nl ...[color=green]
        >> Giulio Neri wrote:
        >>[color=darkred]
        >> > Hi,
        >> > I have a short basic script to upload files. It works fine with small
        >> > files, but with longer files it gets stuck.
        >> >
        >> > Here's the fragment, the input file is loaded in "$file" from an HTML[/color][/color]
        > form[color=green][color=darkred]
        >> > as usual.
        >> >
        >> > ...
        >> > $img_str = fread(fopen($fi le, "r"), filesize($file) );
        >> > $data = addslashes($img _str);
        >> > // --------------------- up to here the execution is correct and fast[/color][/color]
        > (<1[color=green][color=darkred]
        >> > second)
        >> >
        >> > $sql="INSERT INTO $table (".
        >> > " file_name,".
        >> > " file_type,".
        >> > " file_size,".
        >> > " bin_data)".
        >> > " VALUES (".
        >> > " '$file_name',".
        >> > " '$file_type',".
        >> > " '$file_size',".
        >> > " '$data')";[/color]
        >>
        >> Are you aware that the query is very strange?
        >> Since you put ' instead of " around stringliterals, the SQL you produce
        >> might differ somewhat from what you expect.
        >>
        >> Always try:
        >> echo $sql;
        >> before posting to a newsgroup. :P
        >>
        >> You will have something like this:
        >>
        >> INSERT INTO sometable (file_name,file _type,file_size ,bin_data)
        >> VALUES
        >> ('$file_name', '$file_type' etc. etc)
        >>
        >> instead of the expected VALUES for the vars you use.
        >>
        >> Check your ' and "
        >>
        >> Regards,
        >> Erwin Moller
        >>[color=darkred]
        >> > // --------------------- it gets stuck
        >> > here!!!!!!!!!!! !!!!!!!!!!!!!!! !!!!!!!!!!!!!!
        >> > mysql_query($sq l) or die ("SQL error ..$sql");
        >> >
        >> > I have already set the php.ini variables as follows:
        >> > memory_limit = 16M
        >> > upload_max_file size = 6M
        >> >
        >> > I also checked the execution time to max_execution_t ime = 300 (even[/color][/color]
        > though[color=green][color=darkred]
        >> > I don't believe it should be necessary).
        >> > The server is a P4 1.8 GHz, 256MB RAM
        >> >
        >> > Any suggestion? Am I missing out something?
        >> >
        >> > Thanks in advance,
        >> > G.[/color]
        >>[/color][/color]

        Comment

        • Giulio Neri

          #5
          Re: PHP file upload unexpected error - file too large?

          Hi Erwin,
          I did insert a exit($sql); before executing as well as a exit("test");

          in both cases the program did not reach the exit command line

          It is almost definitely something to do with the string concatenation, as
          many other tests I have done show and I don;t know how to get around that!

          Thanks for helping me.



          "Erwin Moller"
          <since_humans_r ead_this_I_am_s pammed_too_much @spamyourself.c om> wrote in
          message news:42077d55$0 $28975$e4fe514c @news.xs4all.nl ...[color=blue]
          > Giulio Neri wrote:
          >[color=green]
          > > Erwin,
          > > the single quotation mark is required in the sql syntax to insert text /
          > > non-numeric values (mysql gives me an error otherwise).
          > >[/color]
          >
          > Right,
          >
          > But did you echo the SQL-string before executing?
          > What came out?
          >
          > Regards,
          > Erwin Moller
          >[color=green]
          > > The real problem here is that the string concatenation fails and I[/color][/color]
          cannot[color=blue][color=green]
          > > make it work...[/color]
          >
          > that is why I advised you to check the ' and " in the first place.
          >
          > Try something like this.
          >
          > $sql="INSERT INTO $table (file_name,file _type,file_size ,bin_data)";
          > $sql.= "VALUES ('".$file_name" ', '".$file_type." ' etc. etc
          >
          > Just use . to concatenate.
          >
          > Good luck.
          > Let me/us know if you succeed.
          >
          > Regards,
          > Erwin Moller
          >
          >[color=green]
          > >
          > > I also tried with something like:
          > >
          > > $sql="hello: $data";
          > >
          > > or
          > >
          > > $sql="hello: " . $data;
          > >
          > > and in both cases it fails (I believe it runs out of memory...).
          > >
          > > The file size is 4MB.
          > >
          > >
          > > Thanks for any additional advise.
          > > G.
          > >
          > >
          > > "Erwin Moller"
          > > <since_humans_r ead_this_I_am_s pammed_too_much @spamyourself.c om> wrote in
          > > message news:420774ff$0 $28990$e4fe514c @news.xs4all.nl ...[color=darkred]
          > >> Giulio Neri wrote:
          > >>
          > >> > Hi,
          > >> > I have a short basic script to upload files. It works fine with small
          > >> > files, but with longer files it gets stuck.
          > >> >
          > >> > Here's the fragment, the input file is loaded in "$file" from an HTML[/color]
          > > form[color=darkred]
          > >> > as usual.
          > >> >
          > >> > ...
          > >> > $img_str = fread(fopen($fi le, "r"), filesize($file) );
          > >> > $data = addslashes($img _str);
          > >> > // --------------------- up to here the execution is correct and[/color][/color][/color]
          fast[color=blue][color=green]
          > > (<1[color=darkred]
          > >> > second)
          > >> >
          > >> > $sql="INSERT INTO $table (".
          > >> > " file_name,".
          > >> > " file_type,".
          > >> > " file_size,".
          > >> > " bin_data)".
          > >> > " VALUES (".
          > >> > " '$file_name',".
          > >> > " '$file_type',".
          > >> > " '$file_size',".
          > >> > " '$data')";
          > >>
          > >> Are you aware that the query is very strange?
          > >> Since you put ' instead of " around stringliterals, the SQL you produce
          > >> might differ somewhat from what you expect.
          > >>
          > >> Always try:
          > >> echo $sql;
          > >> before posting to a newsgroup. :P
          > >>
          > >> You will have something like this:
          > >>
          > >> INSERT INTO sometable (file_name,file _type,file_size ,bin_data)
          > >> VALUES
          > >> ('$file_name', '$file_type' etc. etc)
          > >>
          > >> instead of the expected VALUES for the vars you use.
          > >>
          > >> Check your ' and "
          > >>
          > >> Regards,
          > >> Erwin Moller
          > >>
          > >> > // --------------------- it gets stuck
          > >> > here!!!!!!!!!!! !!!!!!!!!!!!!!! !!!!!!!!!!!!!!
          > >> > mysql_query($sq l) or die ("SQL error ..$sql");
          > >> >
          > >> > I have already set the php.ini variables as follows:
          > >> > memory_limit = 16M
          > >> > upload_max_file size = 6M
          > >> >
          > >> > I also checked the execution time to max_execution_t ime = 300 (even[/color]
          > > though[color=darkred]
          > >> > I don't believe it should be necessary).
          > >> > The server is a P4 1.8 GHz, 256MB RAM
          > >> >
          > >> > Any suggestion? Am I missing out something?
          > >> >
          > >> > Thanks in advance,
          > >> > G.
          > >>[/color][/color]
          >[/color]


          Comment

          • Erwin Moller

            #6
            Re: PHP file upload unexpected error - file too large?

            Giulio Neri wrote:
            [color=blue]
            > Hi Erwin,
            > I did insert a exit($sql); before executing as well as a exit("test");
            >
            > in both cases the program did not reach the exit command line
            >
            > It is almost definitely something to do with the string concatenation, as
            > many other tests I have done show and I don;t know how to get around that!
            >
            > Thanks for helping me.
            >[/color]

            Did you read the rest of my posting?
            It contained an improved $sql statement.
            Try to use it in your situation.

            (I said 2 times, 'Regards, Erwin Moller')
            So that probably made you stop reading after the first. :P
            Sorry.

            Regards,
            Erwin Moller

            Comment

            • Giulio Neri

              #7
              Re: PHP file upload unexpected error - file too large?

              The syntax I used is the same reported in many SQL, MySQL and PHP manuals.

              Anyway I solved the problem:

              1- increased memory available to script
              memory_limit = 16M
              upload_max_file size = 6M

              2- use of unset($temp_var iables) in order to release memory

              3- set mysql configuration file option:
              max_allowed_pac ket=16M

              It all works now...

              Thanks anyway,
              G.


              "Erwin Moller"
              <since_humans_r ead_this_I_am_s pammed_too_much @spamyourself.c om> wrote in
              message news:42078c4c$0 $28985$e4fe514c @news.xs4all.nl ...[color=blue]
              > Giulio Neri wrote:
              >[color=green]
              > > Hi Erwin,
              > > I did insert a exit($sql); before executing as well as a exit("test");
              > >
              > > in both cases the program did not reach the exit command line
              > >
              > > It is almost definitely something to do with the string concatenation,[/color][/color]
              as[color=blue][color=green]
              > > many other tests I have done show and I don;t know how to get around[/color][/color]
              that![color=blue][color=green]
              > >
              > > Thanks for helping me.
              > >[/color]
              >
              > Did you read the rest of my posting?
              > It contained an improved $sql statement.
              > Try to use it in your situation.
              >
              > (I said 2 times, 'Regards, Erwin Moller')
              > So that probably made you stop reading after the first. :P
              > Sorry.
              >
              > Regards,
              > Erwin Moller
              >[/color]


              Comment

              Working...