while upload

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mupparion
Forum Newbie
Posts: 15
Joined: Tue Sep 22, 2009 3:48 am

while upload

Post by mupparion »

Hi,

Ive been trying to make a script that will tell me the current size of an uploaded file.
I thought the way i had gone about it below was pretty spot on, but doesnt seem to work too well

When uploading, instead of the MySQL database being constantly updated with the current file size, all i get is an updated database when the file has finished downloading with the actual file size, which abviously, is no good considering the file has already been uploaded.

Heres what ive got:

<?php
if (strip_tags($_POST['makenews'])){
//////////////START IMAGE UPLOAD

for ($i=0;$i<1;$i++)
{
$target_path = "ups/";
$target_path = $target_path . basename( $_FILES['uploadedfile']['name'][$i]);

$file_name = $_FILES['uploadedfile']['name'][$i];
$file_type = $_FILES['uploadedfile']['type'][$i];
$file_size = $_FILES['uploadedfile']['size'][$i];

while(move_uploaded_file($_FILES['uploadedfile']['tmp_name'][$i], $target_path)) {
$filesize = filesize($_FILES['uploadedfile']['tmp_name'][$i]);
mysql_query("UPDATE `uploads` SET `uploaded`='$filesize' WHERE `id`='1'");
mysql_query("UPDATE `uploads` SET `size`='$file_size' WHERE `id`='1'");

}}
////////////END NEWS ARTICLE INSERT AND DISPLAY CONFIRMATION
echo "<font color='green'>News successfuly added!</font><br>";
}
?>

So is there anyway to constantly update the database with the current size of the file?

Thanks!
dejvos
Forum Contributor
Posts: 122
Joined: Tue Mar 10, 2009 8:40 am

Re: while upload

Post by dejvos »

Hey, you have made a neverending story! You need increment $i in your while cyclus or make some other condition to end your cyclus. The function move_uploaded_files() returns false only if there is a fail in uploading! You still upload same file.
Post Reply