Question: Modify the following two php scripts into one php script that will perform the following operations: - 1. Choose a file to upload by clicking

Modify the following two php scripts into one php script that will perform the following operations:

- 1. Choose a file to upload by clicking the button named "Choose File". The format of the file must be .mp3, .docx, or pdf.

2. After clicking the button named "Submit", the file specified in step 1 will be uploaded.

3. Finally, read the content of the uploaded file.

- print the content of this file

script_1.php

$filename = "read.txt";

$file = fopen($filename, "r");

if( $file == false ) {

die("Error in opening file");

}

$filesize = filesize( $filename);

$filetext = fread($file, $filesize);

fclose( $file );

echo ("File size : $filesize bytes");

echo ("

$filetext
");

?>

script_2.php

if(isset($_FILES['image'])){

$errors= array();

$file_name = $_FILES['image']['name'];

$file_size =$_FILES['image']['size'];

$file_tmp =$_FILES['image']['tmp_name'];

$file_type=$_FILES['image']['type'];

$file_ext=strtolower(end(explode('.',$_FILES['image']['name'])));

$expensions= array("jpeg","jpg","png");

if(in_array($file_ext,$expensions)=== false){

$errors[]="extension not allowed, please choose a JPEG or PNG file.";

}

if($file_size > 2097152){

$errors[]='File size must be excately 2 MB';

}

if(empty($errors)==true){

move_uploaded_file($file_tmp,"images/".$file_name);

echo "Success";

}else{

print_r($errors);

}

}

?>

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!