while upload
Posted: Tue Sep 22, 2009 3:53 am
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!
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!