Php generated wrong format url file path after upload to server
Below is the code for me to generate a unique file Url of each image uploaded and store it to database. //create unique image file name based on micro time and date $now = DateTime::createFromFormat('U.u', microtime(true)); $id = $now->format('YmdHisu'); // Path to move uploaded files $target_path = "uploads"; //the file name $path = "$target_path/$id.jpeg"; // getting server ip address $server_ip = gethostbyname(gethostname()); // final file url that is being uploaded $file_upload_url = 'http://'. $server_ip . '/' . 'abc' . '/' .$path; What I expect for this code should generate the url in json_encode as below: http://126.96.36.199/abc/uploads/20170226041004809200.jpeg But now the problem is it generate the Url but in json_encode result is like below http:\/\/188.8.131.52\/abc\/uploads\/20170226041004809200.jpeg What I tried so far, $file_upload_url = 'http:'. $server_ip . 'abc' .$path; But it not what I want,it become this http:184.108.40.206.1abcuploads\/20170226041515563600.jpeg Can somebody have any idea how to solve this?Or have a better suggestion?
Use str_replace to replace the \ <?php $file_upload_url = "http:\/\/220.127.116.11\/abc\/uploads\/20170226041004809200.jpeg"; $upload_path = str_replace('\\','',$file_upload_url); echo $upload_path; ?> running example http://www.tutorialspoint.com/execute_php_online.php?PID=0Bw_CjBb95KQMZzhZY1lPNGl0MzQ
If you are working on same server then why don't you try to upload file with code snippet- $file_upload_url = realpath($_SERVER["DOCUMENT_ROOT"]). '/abc' . '/' .$path; // you can manage url by - $base_url = isset($_SERVER['HTTPS']) ? 'https://' : 'http://'; $base_url.=$_SERVER['SERVER_ADDR']; $base_url.='/abc/'.$path // now print your url- echo $base_url;
PHP/MYSQL - Select option value not being sent?
Laravel : How to use a parameters in a Form POST to be use in a Route::post?
How to convert object format to json format in php
laravel,how i can change the code to return an array?
How to make At Least Two Field Required to fill in Laravel 5.2
How do I allow PHP to run when the script is not in the URL?
How to check if a file is BEING used, i.e. some command is being executed on the data in that file?
Display profile data from database when login
How to integrate laravel packages into an application
Log into a Django project using Magento user database SSO
Image not show in recyclerview from server
php table exporting it to excel [duplicate]
regex not closing span
How to use GroupBy in nested query in Laravel 5?
Laravel Users table Update
Which classes can I type-hint dependencies for automatic injection in Laravel 5?