Skip to content

Instantly share code, notes, and snippets.

@clasense4
Last active August 29, 2015 13:57
Show Gist options
  • Save clasense4/9800682 to your computer and use it in GitHub Desktop.
Save clasense4/9800682 to your computer and use it in GitHub Desktop.
File Upload Saving dapodik
<?php
/**
* Client Side Upload
* AT : Server VPS Nufaza CloudKilat
* IP : 103.23.20.154
* PATH : /var/www/adminer/upload.php
*/
set_time_limit(600);
$file_name_with_full_path = realpath('./tesfile.txt');
// echo $file_name_with_full_path;
// echo "<hr>";
$post = array('extra_info' => '123456','file_contents'=>'@'.$file_name_with_full_path);
$ch = curl_init();
$target_url = "http://66.nufaza.co.id:8160/";
curl_setopt($ch, CURLOPT_URL,$target_url);
curl_setopt($ch, CURLOPT_POST,1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
$result=curl_exec ($ch);
curl_close ($ch);
echo "<pre>";
print_r($result);
echo "</pre>";
<?php
/**
* Server Upload Receive
* AT : Server Dapodik 66
* IP : 118.98.166.66
* PATH : /var/www/coba/index.php
*/
?>
<html>
<head>
<title>Test upload</title>
</head>
<body>
<?php
if ($_FILES && $_POST){
// $upload_time = time() - $_SERVER['REQUEST_TIME'];
// echo $upload_time;
// echo "<pre>";
// print_r($_FILES);
// echo "</pre>";
// echo "<pre>";
// print_r($_POST);
// echo "</pre>";
error_reporting(E_ERROR);
$uploaddir = "uploads/test/";
$status = 0;
if (!is_dir($uploaddir)) {
if (!mkdir($uploaddir,0777,TRUE)) {
throw new Exception('Gagal membuat direktori '.$uploaddir);
}
}
if (is_uploaded_file($_FILES["file_contents"]["tmp_name"])) {
$uploadfile = $uploaddir . basename($_FILES["file_contents"]["name"]);
if (move_uploaded_file($_FILES["file_contents"]["tmp_name"], $uploadfile)) {
$status = 1;
} else {
$status = 2;
}
} else {
$status = 3;
}
// echo "status = ". $status. "<hr";
switch ($status) {
case 1 : $success = true;
$message = "Berhasil mengunggah file";
break;
case 2 : $success = false;
$message = "Gagal memindahkan file ke direktori tujuan";
break;
case 3 : $success = false;
$message = "Gagal mengupload file";
break;
default: $success = false;
$message = "Gagal mengupload file";
break;
}
// echo Message
$ret = array('success' => $success, 'message' => $message);
// print_r($ret);
// echo "<hr>";
echo json_encode($ret);
// echo "{ 'success' : true, 'message' : 'File ".basename($_FILES["file_contents"]["name"])." berhasil diupload' }"
}
else
{
?>
<h2>Select files to upload</h2>
<form name="upload" method="POST" enctype="multipart/form-data" action="<?php echo $_SERVER['PHP_SELF'] ?>">
<input type="file" name="file_contents"><br>
<input type="submit" name="submit" value="Upload">
<input type="hidden" name="test" value="value">
</form>
<?php
}
?>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment