...

View Full Version : Whats consuming time with this php program?



RogerC
08-27-2006, 03:39 AM
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.


<?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!

saecula
08-27-2006, 04:01 AM
the file is actually uploaded then checked for file size. The upload is the time consumer.

Mwnciau
08-27-2006, 04:51 AM
I would recommend this (http://www.amazon.com/gp/product/0321336577/sr=8-1/qid=1156650595/ref=pd_bbs_1/104-0530176-1056760?ie=UTF8) book if you are just starting with php and mysql.

RogerC
08-27-2006, 05:48 AM
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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum