Philipus Silaen Philipus Silaen - 6 months ago 11
PHP Question

Accessing base url php in hosting cpanel

I am using this in localhost

if (isset($_FILES['image'])) {
if(isset($_POST['directory'])){
$directory = $app->request->post('directory');
$full_directory_path = '../' . $directory;

//Pengecekan folder, sudah tersedia atau belum
if(!is_dir($full_directory_path)){

//Pembuatan folder baru
mkdir($full_directory_path, 0777, true);
}
//Menentukan tempat file akan disimpan
$gambar='http://192.168.0.12/task_manager/'.$directory. '/' . basename($_FILES['image']['name']);
$target_path = $full_directory_path . '/' . basename($_FILES['image']['name']);
if (!move_uploaded_file($_FILES['image']['tmp_name'], $target_path)) {

//File gagal dipindahkan ke server, biasanya karena folder yang dituju tidak tersedia
$response['kode'] = 1;
$response['pesan'] = "File tidak dapat dipindahkan ke server";
echo json_encode($response);
}else{
// File berhasil diupload
$response['kode'] = 2;
$response['gili'] = $gambar;
$response['pesan'] = "File berhasil diupload";
echo json_encode($response);
}
}else{

}
} else {

//Jika file tidak terkirim dari android
$response['kode'] = 0;
$response['pesan'] = 'File tidak terkirim ke server';
echo json_encode($response);
}


and it works perfectly, but when I put it in my hosting it cannot insert image. I think it is because of this

$full_directory_path = '../' . $directory;


how can I access base url in cpanel? did it true like that? cause in localhost it is works perfectly

this is my structure path : public_html/api/task_manager/v1/index.php
what I want is making new path under public_html so how can I change my url like this
$full_directory_path = 'http://myweb/' . $directory;

$directory will make new directory

Answer

Try this:

$full_directory_path = $_SERVER["DOCUMENT_ROOT"] . '/task_manager/'. $directory;
Comments