Update uploaded file help
am 24.11.2010 20:18:48 von Estelle George--_47a76e33-97da-4466-be8e-e0fb2478ca51_
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
Hi all=2C
=20
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!
=20
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.
=20
Here's my code:
// This page allows users to edit or delete existing URL records.
=20
=20
$page_title =3D 'Edit a file'=3B
=20
=20
// 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=
!
=20
include ('./includes/footer.html')=3B
exit()=3B // Terminate execution of the script.
}//
=20
=20
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
//
=20
if (isset($_POST['submitted'])) { // Handle the form.
//
=20
if ($_POST['which'] == 'delete') { // Delete the record.
// This part is working fine.
} else { // Edit the uploaded file .
for ($i =3D 0=3B $i < $counter=3B $i++) { // Handle the uploaded file=
..
=20
$filename =3D 'upload' . $i=3B
$description =3D 'description' . $i=3B
=20
// Check for a file.
=20
=20
if (isset($_FILES[$filename]) && ($_FILES[$filename]['error'] !=
=3D 2)) {
// Check for a description=20
=20
if (!empty($_POST[$description])) {
$d =3D "'" . escape_data($_POST [$description]) . "'"=
=3B
} else {
$d =3D 'NULL
}
=20
// Update the record to the database.
=20
=20
$query =3D "UPDATE uploads SET file_name=3D'$name',
file_size=3D'$size'=2C file_type=3D'$type'=2C descripti=
on=3D'$d' WHERE=20
upload_id=3D$uid"=3B
$result =3D mysql_query ($query)=3B
=20
if ($result) {
=20
// Return the upload_id from the database.
$upload_id =3D mysql_insert_id()=3B
=20
// Move the file over.
if (move_uploaded_file($_FILES[$filename]['tmp_name'=
]=2C "uploads/$upload_id")) {
echo '
New file ' . ($i + 1) . ' has bee=
n uploaded!
} else { // File could not be moved.
echo '
File ' . ($i +=
1) . 'could not be moved.
=20
}//end move_uploaded_file
=20
} else { // If the query did not run OK
=20
=20
echo '
Yoursubmission could not be=
processed due to a system error. We apologize
for any inconvenience.
}//end if(result)
=20
} // End of if (isset($the_file)...
=20
} // End of FOR loop. =20
=20
} // End of Edit/Delete if-else.
=20
} // End of the main submitted conditional.
=20
// --------- DISPLAY THE FORM ---------
=20
=20
=20
//Retrieve the uploads's current information.=20
=20
$query =3D "SELECT file_name=2C ROUND(file_size/1024) AS fs=2C file_type=
,
description=2C DATE_FORMAT(date_entered=2C '%e %M %Y') AS d FRO=
M 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
Thanks in advance!
Estelle
=
--_47a76e33-97da-4466-be8e-e0fb2478ca51_--