Outline ·
[ Standard ] ·
Linear+
Saving image file in server, doing in localhost
TSsundaemanis
|
Feb 14 2017, 04:39 PM, updated 8y ago
|
New Member
|
Hi, I'm having problem with php to save file in the web folder. (I'm doing it in local server) » Click to show Spoiler - click again to hide... « CODE function uploadFile () { //Getting the server ip $server_ip = gethostbyname(gethostname()); $upload_path = 'uploads/'; $upload_url = 'http://'.$server_ip.'/'.$upload_path;
if (!isset($_FILES['image'])) { echo "No files uploaded!!"; return; }
//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 . getFileName() . '.' . $extension; //file path to upload in the server $file_path = $upload_path . getFileName() . '.'. $extension;
try{ //saving the file move_uploaded_file($_FILES['image']['tmp_name'],$file_path);
//filling response array with values $response['error'] = false; $response['url'] = $file_url; $response['name'] = $name;
return $file_url; //if some error occurred }catch(Exception $e){ $response['error']=true; $response['message']=$e->getMessage(); echo "Fuck error!"; } //displaying the response echo json_encode($response);
}
this is the message that I get. QUOTE { "error":true, "message":"move_uploaded_file(uploads\/img-20170214-58a2c07ee551d.jpg): failed to open stream: No such file or directory" } Already googling for some solutions. Many says the include directory is the problem. help :<
|
|
|
|
Ryutaro
|
Feb 14 2017, 05:07 PM
|
|
i dont code in php...but i also suspect its the directory causing the problem.. did u saw the message part where uploads\/img.... part?a valid url shudnt have '\''/' together
meaning to say the directory contains error hence causing the file couldnt be open because it couldnt locate ur file in the first place
|
|
|
|