Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Aug 2006
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Whats consuming time with this php program?

    Hi all!

    I’m “real” new to PHP, so.......

    After several battles with some cgi code(I'm new to that also), I ran across some PHP code in a post by “mlseim” for uploading files, it really works very nicely. Thanks mlseim!

    I don’t understand much of the syntax PHP uses, but I have been programming for some time (C-C++) so the flow looks somewhat familiar. I need to dig up a good book on PHP.

    A question I have is based on this code.

    Code:
    <?php
    
    // file phpinfo.php
    //phpinfo();
    
    ini_set('upload_max_filesize','2M');
    
    //Get the number of files to be uploaded
    $num = $_POST['num'];
    
    //Start the Loop
    for ($x = 1; $x <= $num; $x++)
    {
    	//Make sure a file has been selected for upload
    	if (is_uploaded_file($_FILES['file'.$x]['tmp_name']))
    	{
    		//Get the size of the current file
    		$size = $_FILES['file'.$x]['size'];
    
    		//Display message
    		echo "Filesize: ".$size . "<BR>";
    
    
    		//Make sure that this file is <= to 500KB (or whatever size limit you want).
    		if ($size <= 500000)
    		{
    			//Move the uploaded file ... "uploads/" is where they will be stored.
    			if (move_uploaded_file($_FILES['file'.$x]['tmp_name'],'uploads/'.$_FILES['file'.$x]['name']))
    			{
    				//Display message
    				echo "File: ".$_FILES['file'.$x]['name'] . " uploaded.<BR>";
    			}
    			else
    			{
    				//Unable to move file
    				echo "File: ".$_FILES['file'.$x]['name']. " error moving file.<BR>";
    			}
    		}
    		else
    		{
    			//File too large
    			echo "File: " . $_FILES['file'.$x]['name'] . " File Too Large.<BR>";
    		}
    	}
    	else
    	{
    		//No file selected
    		echo "No File Selected.<BR>";
    	}
    } //End of loop
    ?>

    There is a filesize limit imposed by the program, when the filesize exceeds the limit, it looks like the program has nothing it needs to do, and the functionality should move to exit. However, even though the file will not be uploaded, there is still a time consumption that is linear with the file size that was sent to the process? For example: if I try to upload a file that 8mb in size, the function will not quickly report the limit has been exceeded, but goes through "some" process that may take a couple of minutes.

    I don't understand what's happening?

    Thank for any info!

  • #2
    New Coder
    Join Date
    Aug 2006
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts
    the file is actually uploaded then checked for file size. The upload is the time consumer.

  • #3
    Regular Coder
    Join Date
    May 2006
    Location
    Wales
    Posts
    820
    Thanks
    1
    Thanked 82 Times in 79 Posts
    I would recommend this book if you are just starting with php and mysql.

  • #4
    New to the CF scene
    Join Date
    Aug 2006
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    It did seem like that's what was happening. Is there no way to get the filesize to the server before an upload process happens?

    Thanks for the info and the recomendation on the book, the reviews look excellent. I'll snatch a copy.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •