I am using GoDaddy for my hosting account and I am trying to get a file to upload correctly.
Here is my PHP..
<?php
$listingId = $_POST['listingId'];
$upload_path = 'public_html/_/hostname.com/stash/images/';
$upload_url = 'https://www.hostname.com/stash/images/';
//response array
$response = array();
if($_SERVER['REQUEST_METHOD']=='POST'){
//checking the required parameters from the request
if(isset($_POST['name']) and isset($_FILES['image']['name'])){
//getting name from the request
$name = $_POST['name'];
//getting file info from the request
$fileinfo = pathinfo($_FILES['image']['name']);
//getting the file extension
$extension = $fileinfo['extension'];
//file url to store in the database
$file_url = $upload_url . $listingId . '.' . $extension;
//file path to upload in the server
$file_path = $upload_path . $listingId . '.'. $extension;
//trying to save the file in the directory
try{
//saving the file
move_uploaded_file($_FILES['image']['tmp_name'],$file_path);
$response['message'] = "idk if this worked";
//if some error occurred
}catch(Exception $e){
$response['error']=true;
$response['message']=$e->getMessage();
}
echo json_encode($response);
}else{
$response['error']=true;
$response['message']='Please choose a file';
}
}
?>
The problem I am facing is that its not uploading the file to the specific folder. The folder/location is 777.
I tried using postman to send a request and it's not working. Any help would be greatly appreciated.