Need help with file upload

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

    Need help with file upload

    Hello!
    I again need your help, just can't understand whats going on.
    Got this upload pictures form and it's having problem handling large
    files (~1.5 - 2 MB).
    Everything works fine if i just upload files, like this:

    copy ($myfile, $uploadfolder . "/" . $myfile_name);

    Everything works fine, it can process large files and everything,
    but i need to make sure that people only upload pictures, so i change
    it to this:

    $fext = strrchr($myfile _name,".");
    if($fext==".jpg " || $fext==".jpeg")
    {
    copy ($myfile, $uploadfolder . "/" . $myfile_name);
    }

    After this modification it can only process relatively small files,
    around 200-300 kb, everytime i try to upload a large file it just does
    not do anything,
    it looks like the file is being uploaded and then nothing, the file is
    not there...
    I tried setting
    set_time_limit( 0);
    but it did not change anything...
    if i check the extension it does not upload large files, if i don't -
    it does...
    Could someone help me please, thank you!

    P.S. Whats better to use, copy or move_uploaded_f ile? Or it just does
    not matter?
    Thanks a lot again!
  • dr zoidberg

    #2
    Re: Need help with file upload

    Tihon wrote:
    [color=blue]
    > Hello!
    > I again need your help, just can't understand whats going on.
    > Got this upload pictures form and it's having problem handling large
    > files (~1.5 - 2 MB).
    > Everything works fine if i just upload files, like this:
    >
    > copy ($myfile, $uploadfolder . "/" . $myfile_name);
    >
    > Everything works fine, it can process large files and everything,
    > but i need to make sure that people only upload pictures, so i change
    > it to this:
    >
    > $fext = strrchr($myfile _name,".");
    > if($fext==".jpg " || $fext==".jpeg")
    > {
    > copy ($myfile, $uploadfolder . "/" . $myfile_name);
    > }
    >
    > After this modification it can only process relatively small files,
    > around 200-300 kb, everytime i try to upload a large file it just does
    > not do anything,
    > it looks like the file is being uploaded and then nothing, the file is
    > not there...
    > I tried setting
    > set_time_limit( 0);
    > but it did not change anything...
    > if i check the extension it does not upload large files, if i don't -
    > it does...
    > Could someone help me please, thank you!
    >
    > P.S. Whats better to use, copy or move_uploaded_f ile? Or it just does
    > not matter?
    > Thanks a lot again![/color]

    Maybe you have some upload limit set on your server. Check your php.ini
    file.

    Comment

    • Shawn Wilson

      #3
      Re: Need help with file upload

      Tihon wrote:[color=blue]
      >
      > Hello!
      > I again need your help, just can't understand whats going on.
      > Got this upload pictures form and it's having problem handling large
      > files (~1.5 - 2 MB).
      > Everything works fine if i just upload files, like this:
      >
      > copy ($myfile, $uploadfolder . "/" . $myfile_name);
      >
      > Everything works fine, it can process large files and everything,
      > but i need to make sure that people only upload pictures, so i change
      > it to this:
      >
      > $fext = strrchr($myfile _name,".");
      > if($fext==".jpg " || $fext==".jpeg")
      > {
      > copy ($myfile, $uploadfolder . "/" . $myfile_name);
      > }[/color]

      Have you considered CaSe SenSITivity? I'd try something like:

      preg_match("/(jpeg|jpg)$/i", $_FILES['myfile']['name']);

      Regards,
      Shawn
      --
      Shawn Wilson
      shawn@glassgian t.com

      Comment

      • Carlos Marangon

        #4
        Re: Need help with file upload

        Try this

        upload.php
        --------
        <?
        /* Max filesize: */
        if($arquivo_siz e > 1024000) {
        print "<SCRIPT> alert('File cannot to be larger than 1 Mb');
        window.history. go(-1); </SCRIPT>\n";
        exit;
        }
        /* Define target dir to store uploaded files */
        if (!empty($arquiv o) and is_file($arquiv o)) {
        $caminho="/full/path/to/the/dir/";
        $caminho=$camin ho.$arquivo_nam e;
        /* Define the kind of file allowed */
        if ((eregi(".DOC$" , $arquivo_name)) || (eregi(".zip$",
        $arquivo_name)) ){
        copy($arquivo,$ caminho);
        print "<h1><center>Fi le was sent!</center></h1>";
        }
        else{
        print "<h1><center>Fi le was not sent!</center></h1>";
        print "<h2><font color='#FF0000' ><center>File type not
        allowed!</center></font></h2>";
        }
        }
        ?>

        --------
        upload.html

        <html>
        <head>
        <script language="JavaS cript">
        <!--
        function teste(){
        if (document.uploa d.arquivo.value =="") {
        alert("Arquivo para upload não informado!")
        document.upload .arquivo.focus( )
        return false
        }
        }
        //-->
        </script>
        </head>
        <body>
        <h2>Upload Simples</h2><br>
        <form name="upload" action="upload. php" method="post"
        enctype="multip art/form-data" onsubmit="retur n teste()">
        <input type="file" name="arquivo" size="60"><br>
        <br>
        <input type="submit" name="enviar" value="Upload!" >
        </form>
        </center>
        </body>
        </html>

        =============

        []

        Carlos

        tihon@ziplip.co m (Tihon) wrote in message news:<7da634b3. 0402231508.56c7 fb8e@posting.go ogle.com>...[color=blue]
        > Hello!
        > I again need your help, just can't understand whats going on.
        > Got this upload pictures form and it's having problem handling large
        > files (~1.5 - 2 MB).
        > Everything works fine if i just upload files, like this:
        >
        > copy ($myfile, $uploadfolder . "/" . $myfile_name);
        >
        > Everything works fine, it can process large files and everything,
        > but i need to make sure that people only upload pictures, so i change
        > it to this:
        >
        > $fext = strrchr($myfile _name,".");
        > if($fext==".jpg " || $fext==".jpeg")
        > {
        > copy ($myfile, $uploadfolder . "/" . $myfile_name);
        > }
        >
        > After this modification it can only process relatively small files,
        > around 200-300 kb, everytime i try to upload a large file it just does
        > not do anything,
        > it looks like the file is being uploaded and then nothing, the file is
        > not there...
        > I tried setting
        > set_time_limit( 0);
        > but it did not change anything...
        > if i check the extension it does not upload large files, if i don't -
        > it does...
        > Could someone help me please, thank you!
        >
        > P.S. Whats better to use, copy or move_uploaded_f ile? Or it just does
        > not matter?
        > Thanks a lot again![/color]

        Comment

        • Tihon

          #5
          Re: Need help with file upload

          area48@hotmail. com (Carlos Marangon) wrote in message news:<2cfc228.0 402240914.49b61 955@posting.goo gle.com>...[color=blue]
          > Try this
          >
          > upload.php
          > --------
          > <?
          > /* Max filesize: */
          > if($arquivo_siz e > 1024000) {
          > print "<SCRIPT> alert('File cannot to be larger than 1 Mb');
          > window.history. go(-1); </SCRIPT>\n";
          > exit;
          > }
          > /* Define target dir to store uploaded files */
          > if (!empty($arquiv o) and is_file($arquiv o)) {
          > $caminho="/full/path/to/the/dir/";
          > $caminho=$camin ho.$arquivo_nam e;
          > /* Define the kind of file allowed */
          > if ((eregi(".DOC$" , $arquivo_name)) || (eregi(".zip$",
          > $arquivo_name)) ){
          > copy($arquivo,$ caminho);
          > print "<h1><center>Fi le was sent!</center></h1>";
          > }
          > else{
          > print "<h1><center>Fi le was not sent!</center></h1>";
          > print "<h2><font color='#FF0000' ><center>File type not
          > allowed!</center></font></h2>";
          > }
          > }
          > ?>
          >
          > --------
          > upload.html
          >
          > <html>
          > <head>
          > <script language="JavaS cript">
          > <!--
          > function teste(){
          > if (document.uploa d.arquivo.value =="") {
          > alert("Arquivo para upload não informado!")
          > document.upload .arquivo.focus( )
          > return false
          > }
          > }
          > //-->
          > </script>
          > </head>
          > <body>
          > <h2>Upload Simples</h2><br>
          > <form name="upload" action="upload. php" method="post"
          > enctype="multip art/form-data" onsubmit="retur n teste()">
          > <input type="file" name="arquivo" size="60"><br>
          > <br>
          > <input type="submit" name="enviar" value="Upload!" >
          > </form>
          > </center>
          > </body>
          > </html>
          >
          > =============
          >
          > []
          >
          > Carlos[/color]

          Thank you so very much Carlos!
          I still don't understand why but your version works, uploads any size i want!
          Must be the way you check for file extension,
          Thank you very much!

          Comment

          Working...