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

Display an image in a <div>, jQuery
mySQL table linking , group linked to other members lists, the displaying all members
Using “includes” in an OO PHP Class
Small regex question in PHP
I18n of Zend_Form values and errors
Is it possible to enable an extension programmatically in PHP?
How to deal with m2m relationship(posts and tags) by doctrine(in symfony)?
Yii framework - how to specify the same access rules for all controllers of the module?
Automated builds and STDIN
Weird PHP behavior: won't assign the integer 8 to a variable
Echo row 30 with php from sql result?
PHP 5 SOAP client returns NULL when WSDL-provided function is called
double $ statement in php
Kevin Luck's jQuery Date Picker plugin - Set the end date dynamically
mySQL query fails when read from file or web
HTML-PHP Uploader Query

Categories

HOME
libgdx
mod-rewrite
apache-nifi
blast
dotnetnuke
jms
transactions
operating-system
magento-2.0
bing-search
moodle-api
linker
repair
stored-procedures
angular2-template
msmq
cqrs
parsley.js
circleci
multi-step
amazon-elb
sql-injection
user-defined-types
gravity
checkout
nose
social-tables
anova
multi-upload
quantitative-finance
cellular-network
network-analysis
copy-protection
nic
rspec-rails
osx-lion
autoencoder
numerics
bluemixtools
assemblies
praat
right-click
utf
dbcc
web-inspector
jshint
daz3d
bit-shift
spongycastle
realstudio
android-5.0-lollipop
entropy
stateless-session-bean
dex
openerp-6
google-shopping-api
petsc
openquery
spring-mongo
facebook-ios-sdk
gdl
lovefield
phpquery
boost-proto
mixins
360-degrees
replicaset
dynamics-ax-2012-r2
darwin
textscan
ampersand
fuseesb
text-align
relationships
screwturn
redpitaya
windows-taskbar
mft
eclim
ggts
disjoint-union
html-frames
days
semicolon
smartfox
email-verification
multiscaleimage
struts2-json-plugin
voice-recording
coordinate
uipangesturerecognizer
exponent
memory-pool
infopath-2007
hungarian-notation
ccnet-config
powergui
sqlsitemapprovider
prism-2
html-generation

Resources

Database Users
RDBMS discuss
Database Dev&Adm
javascript
java
csharp
php
android
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App