php


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://111.111.11.1/abc/uploads/20170226041004809200.jpeg
But now the problem is it generate the Url but in json_encode result is like below
http:\/\/111.111.11.1\/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:111.111.11.1.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:\/\/111.111.11.1\/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;

Related Links

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?

Categories

HOME
google-chrome
ionic2
macos-sierra
automapper
couchdb
bots
selenium-builder
dafny
embedded-resource
odata
tabs
web2py
firebase-dynamic-links
joomla3.2
polymer-2.x
siesta
slide
alljoyn
responsivevoice
global-variables
twisted
synthesis
phonegap-build
web-deployment
checkout
salt-cloud
bluemix-mobile-services
sharedpreferences
nurbs
uri
bobo-browse.net
sendmessage
mongoengine
nest
apptentive
xerces-c
djcelery
ms-dos
python-jira
slideshow
yoast
optionaldataexception
minikube
absolute
swift2.3
spring.net
pen
stateless-session-bean
http4s
prefetch
gapi
libharu
mathjs
jenkins-workflow
adp
powerpoint-2013
noclassdeffounderror
adjacency-list
gridbaglayout
as3-api
diawi
phpquery
textpattern
android-mapview
perceptron
fanotify
gluon-desktop
gitlab-omnibus
netdatacontractserializer
karma-coverage
dbmigrate
erlog
rubber
zend-mail
xml-signature
window-resize
inequality
producer
inputbox
back
object-code
mobile-country-code
webautomation
fileshare
sql-function
frontbase
rautomation
sql-view
instance-variables
image-scanner
firebird1.5
prototypal-inheritance
motodev-studio
page-curl
mygeneration
reliability
eventaggregator
html-components
eai
gtktextview
downcasting
xap
ning
motif
comment-conventions
isapi-redirect

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App