Edit an uploded file help

Edit an uploded file help

am 24.11.2010 15:50:40 von Estelle George

--_8143d454-9506-4f1f-8c7e-231de1aa8443_
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable








Hi all=2C

I am new to php=2C I am just learning it at the moment. I hope you can help=
me with my code.
Thanks in advance!

I want the page to allow users to edit or delete an existing uploaded file.=
=20
But after testing the script in the browser the delete option is working 1=
0 out 0f 10;
but the edit is not. I don't know what I am doing wrong.

Here's my code:

// This page allows users to edit or delete existing URL records.

=20
$page_title =3D 'Edit a file'=3B
include ('./includes/header.html')=3B

// Check for a URL ID.
if (isset($_GET['uid'])) { // Page is first accessed.
$uid =3D (int) $_GET['uid']=3B
} elseif (isset($_POST['uid'])) { // Form has been submitted.
$uid =3D (int) $_POST['uid']=3B
} else { // Big problem.
$uid =3D 0=3B
}
//
if ($uid <=3D 0) { // Do not proceed!
echo '

This page has been accessed incorrectly=
!

'=3B

include ('./includes/footer.html')=3B
exit()=3B // Terminate execution of the script.
}//


require_once ('./mysql_connect.php')=3B // Connect to the database.
=20
$counter=3D1=3B
$name=3D $_FILES[$filename]['name']=3B
$size=3D$_FILES[$filename]['size']=3B
$type=3D$_FILES[$filename]['type']=3B
$temp_name=3D$_FILES[$filename]['temp_name']=3B
$error=3D$_FILES[$filename]['error']=3B
//

if (isset($_POST['submitted'])) { // Handle the form.
//



if ($_POST['which'] == 'delete') { // Delete the record.



// This part is working fine.



} else { // Edit the uploaded file .

=20

for ($i =3D 0=3B $i < $counter=3B $i++) { // Handle the uploaded f=
ile.

$filename =3D 'upload' . $i=3B


$description =3D 'description' . $i=3B

=20

// Check for a file.


if (isset($_FILES[$filename]) && ($_FILES[$filename]['error'] !=
=3D 2)) {





// Check for a description=20


if (!empty($_POST[$description])) {


$d =3D "'" . escape_data($_POST [$description]) . "'"=3B





} else {


$d =3D 'NULL'=3B


}





// Update the record to the database.


$query =3D "UPDATE uploads SET file_name=3D'$name',
file_size=3D'$size'=2C file_type=3D'$type'=2C description=3D'$d' WHERE=20
upload_id=3D$uid"=3B


$result =3D mysql_query ($query)=3B





if ($result) {





// Return the upload_id from the database.


$upload_id =3D mysql_insert_id()=3B





// Move the file over.


if (move_uploaded_file($_FILES[$filename]['tmp_name']=2C "up=
loads/$upload_id")) {


=20





echo '

File number ' . ($i + 1) . ' has been uploaded!=

'=3B





} else { // File could not be moved.





echo '

File number ' .
($i + 1) . ' could not be moved.

'=3B





// Remove the record from the database.


$query =3D "DELETE FROM uploads WHERE upload_id =3D $upl=
oad_id"=3B


$result =3D mysql_query ($query)=3B





=20


}//end move_uploaded_file





} else { // If the query did not run OK


echo '

Your=20
submission could not be processed due to a system error. We apologize=20
for any inconvenience.

'=3B


=20


=20


}//end if(result)





} // End of if (isset($the_file)...


} // End of FOR loop. =20


=20


} // End of Edit/Delete if-else.







} // End of the main submitted conditional.







// --------- DISPLAY THE FORM ---------



//Retrieve the uploads's current information.=20



$query =3D "SELECT file_name=2C ROUND(file_size/1024) AS fs=2C file_typ=
e,
description=2C DATE_FORMAT(date_entered=2C '%e %M %Y') AS d FROM uploads=20
WHERE upload_id=3D$uid"=3B



$result =3D mysql_query ($query)=3B



=20



//get all of the information first record



=20



list($file_name=2C $fs=2C $file_type=2C $d=2C $de)=3D mysql_fetch_array=
($result=2C MYSQL_NUM)=3B



=20



=20



=20



=20



=20



?>











Edit a File:







Select One: edit"



checked=3D"checked" /> Edit alue=3D"delete" />



Delete








=20



//Retrieve the uploads's current information.=20



$query =3D "SELECT file_name=2C ROUND(file_size/1024) AS fs=2C file_typ=
e,
description=2C DATE_FORMAT(date_entered=2C '%e %M %Y') AS de FROM uploads=20
WHERE upload_id=3D$uid"=3B



$result =3D mysql_query ($query)=3B



=20



//print the current file's information in the browser




=20




while ($row =3D mysql_fetch_array($result=2C MYSQL_ASSOC)) {




=20




echo ' =3D"3" align=3D"center">
























'=3B




=20









// Display each record.




echo "









=20














=20




\n"=3B




}




=20




=20









?>









for ($i =3D 0=3B $i < $counter=3B $i++) {





echo '

File: .. '" />







Description: name=3D"description' . $i . '" cols=3D"40"=20
rows=3D"5">'.$d.'


'=3B





}





?>





=20

























echo '













'=3B






?>






=3D"Submit" />



























include ('./includes/footer.html')=3B






?>=20




=20








for ($i =3D 0=3B $i < $counter=3B $i++) {




echo '

File: .. '" />






Description: name=3D"description' . $i . '" cols=3D"40"=20
rows=3D"5">'.$d.'


'=3B




}




?>




=20





















echo '











'=3B





?>





=3D"Submit" />























include ('./includes/footer.html')=3B





?> =20


=20
Thanks in advance!






=20
=20



=20

=20

=20



=20

=20

=20



=20
=20

=20
=

--_8143d454-9506-4f1f-8c7e-231de1aa8443_--

File Name nt> File Size font> Upload Date font>
{$row['file_name']} {$row ['fs']}kb {$row ['de']}