Philipus Silaen Philipus Silaen - 1 year ago 97
PHP Question

Accessing base url php in hosting cpanel

I am using this in localhost

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

//Pengecekan folder, sudah tersedia atau belum

//Pembuatan folder baru
mkdir($full_directory_path, 0777, true);
//Menentukan tempat file akan disimpan
$gambar=''.$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);
// File berhasil diupload
$response['kode'] = 2;
$response['gili'] = $gambar;
$response['pesan'] = "File berhasil diupload";
echo json_encode($response);

} 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 Source

Try this:

$full_directory_path = $_SERVER["DOCUMENT_ROOT"] . '/task_manager/'. $directory;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download