Return to Snippet

Revision: 73412
at July 8, 2018 05:21 by devquora

Initial Code
	//if no errors...
		//now is the time to modify the future file name and validate the file
		$new_file_name = strtolower($_FILES['file']['tmp_name']); //rename file
		if($_FILES['file']['size'] > (1024000)) //can't be larger than 1 MB
			$valid_file = false;
			$message = 'Oops!  Your file\'s size is to large.';
		//if the file has passed the test
			//move it to where we want it to be
			move_uploaded_file($_FILES['file']['tmp_name'], 'uploads/'.$new_file_name);
			$message = 'File uploaded successfully.';
	//if there is an error...
		//set that to be the returned message
		$message = 'Something got wrong while uploading file:  '.$_FILES['file']['error'];

Initial URL

Initial Description
Code to upload a file in PHP

Initial Title
Code to upload a file in PHP

Initial Tags
php, file, code

Initial Language