Ng2-file upload with PHP backend #945

Open
opened 2017-12-20 11:46:07 +00:00 by shajeermhmmd · 1 comment
shajeermhmmd commented 2017-12-20 11:46:07 +00:00 (Migrated from github.com)

Anybody can help me to upload the files to server folder using PHP, Now I am getting empty as post data, I used the normal scenario described in the tutorial... please help me...

Anybody can help me to upload the files to server folder using PHP, Now I am getting empty as post data, I used the normal scenario described in the tutorial... please help me...
sambanthar commented 2017-12-21 09:29:56 +00:00 (Migrated from github.com)

$path = '/var/www/html/uploads/';
if (isset($_FILES['file'])) {
$originalName = $_FILES['file']['name'];
$ext = '.'.pathinfo($originalName, PATHINFO_EXTENSION);
$generatedName = md5($_FILES['file']['tmp_name']).$ext;
$filePath = $path.$generatedName;

		  if (!is_writable($path)) {
			echo json_encode(array(
			  'status' => false,
			  'msg'    => 'Destination directory not writable.'
			));
			exit;
		  }
		 
		  if (move_uploaded_file($_FILES['file']['tmp_name'], $filePath)) {
			echo json_encode(array(
			  'status'        => true,
			  'originalName'  => $originalName,
			  'generatedName' => $generatedName
			));
		  }
		}
		else {
		  echo json_encode(
			array('status' => false, 'msg' => 'No file uploaded.')
		  );
		  exit;
		}
$path = '/var/www/html/uploads/'; if (isset($_FILES['file'])) { $originalName = $_FILES['file']['name']; $ext = '.'.pathinfo($originalName, PATHINFO_EXTENSION); $generatedName = md5($_FILES['file']['tmp_name']).$ext; $filePath = $path.$generatedName; if (!is_writable($path)) { echo json_encode(array( 'status' => false, 'msg' => 'Destination directory not writable.' )); exit; } if (move_uploaded_file($_FILES['file']['tmp_name'], $filePath)) { echo json_encode(array( 'status' => true, 'originalName' => $originalName, 'generatedName' => $generatedName )); } } else { echo json_encode( array('status' => false, 'msg' => 'No file uploaded.') ); exit; }
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: dc/ng2-file-upload#945