Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I have the first 3 steps. I am trying to store files is a subdirectory name .tmp

ID: 3546074 • Letter: I

Question

I have the first 3 steps. I am trying to store files is a subdirectory name .tmpFiles and the 3 steps below it

Create a set of php programs to allow users of the web site to upload various files to our server.                 

I have the first 3 steps. I am trying to store files is a subdirectory name .tmpFiles and the 3 steps below it Create a set of php programs to allow users of the web site to upload various files to our server. Details: use the standard "php upload" routine be sure to allow for file size up to 300 megabytes limit files to type: txt, pdf, dxf, png store the files in a subdirectory: .tmpFiles [be sure to use the "dot" in front of the file name rename the files when uploaded to a unique name, in case two users happen to upload the same file, but retain the extension [txt, pdf, dxf, add a "list" feature to show what files are in the temp folder add one "bell or whistle" that comes to mind as a "nice to have" feature of this exercise

Explanation / Answer

<?php

$t=time();

$target = ".tmpFiles/".$t.$_FILES["file"]["name"];//no chance for file name conflicts. Since we are adding time stamp before every file name
$ok=1;
//This is our size condition
if ($uploaded_size > 314572800){
echo "Your file is too large. We have a 300MB limit.<br>";
$ok=0;
}

$types = array('image/png', 'application/pdf', 'application/dxf' , 'application/txt');

if (in_array($_FILES['uploaded']['type'], $types)) {
// file is okay continue
} else {
$ok=0;
}

//Here we check that $ok was not set to 0 by an error
if ($ok==0){
Echo "Sorry your file was not uploaded. It may be the wrong filetype. We only allow pdf, png, dxf, txt filetypes.";
}

//If everything is ok we try to upload it
else{
if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)){
echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded";
}
else{
echo "Sorry, there was a problem uploading your file.";
}
}
?>

------------------------------------------------

list.php starts here. This program lists all the files in the folder .tmpFiles