php file uploading cannot retrieve the path
I am trying to upload photos in to folder uploads and its path to be recorded under photo in DB. This is my code:
$folder ="uploads";
$destFile = $folder . basename($_FILES["photo"]["name"]);
$sourdeFile = $_FILES["photo"]["tmp_name"];
if(move_uploaded_file($sourdeFile,$destFile)){
echo "File has been uploaded";
$photo = $destFile;
}else{
echo $_FILES['photo']['error'];
$photo = "images/default.png";
}
When I upload photos they successfully uploaded into folder but the problem is its path recorded as follow :
uploads42141402_1866830986743601_8538143552767524864_n.jpg
But to view photos in a page there should be next to uploads. So I tried to change my code as follow.
$folder = "uploads";
But it generates this error
Can anyone say how to fix this ?
php file file-upload
add a comment |
I am trying to upload photos in to folder uploads and its path to be recorded under photo in DB. This is my code:
$folder ="uploads";
$destFile = $folder . basename($_FILES["photo"]["name"]);
$sourdeFile = $_FILES["photo"]["tmp_name"];
if(move_uploaded_file($sourdeFile,$destFile)){
echo "File has been uploaded";
$photo = $destFile;
}else{
echo $_FILES['photo']['error'];
$photo = "images/default.png";
}
When I upload photos they successfully uploaded into folder but the problem is its path recorded as follow :
uploads42141402_1866830986743601_8538143552767524864_n.jpg
But to view photos in a page there should be next to uploads. So I tried to change my code as follow.
$folder = "uploads";
But it generates this error
Can anyone say how to fix this ?
php file file-upload
You have the wrong slash should be /
– rpm192
Nov 15 '18 at 8:06
i did it too.But still same error
– Nipun Tharuksha
Nov 15 '18 at 8:07
have you given read-write permission to the upload folder? also, check the uploads folder should be inside carsale/controller folder
– Sayed Mohd Ali
Nov 15 '18 at 8:34
i did it too.Moved the folder into controller folder and change.but error is till same
– Nipun Tharuksha
Nov 15 '18 at 9:43
add a comment |
I am trying to upload photos in to folder uploads and its path to be recorded under photo in DB. This is my code:
$folder ="uploads";
$destFile = $folder . basename($_FILES["photo"]["name"]);
$sourdeFile = $_FILES["photo"]["tmp_name"];
if(move_uploaded_file($sourdeFile,$destFile)){
echo "File has been uploaded";
$photo = $destFile;
}else{
echo $_FILES['photo']['error'];
$photo = "images/default.png";
}
When I upload photos they successfully uploaded into folder but the problem is its path recorded as follow :
uploads42141402_1866830986743601_8538143552767524864_n.jpg
But to view photos in a page there should be next to uploads. So I tried to change my code as follow.
$folder = "uploads";
But it generates this error
Can anyone say how to fix this ?
php file file-upload
I am trying to upload photos in to folder uploads and its path to be recorded under photo in DB. This is my code:
$folder ="uploads";
$destFile = $folder . basename($_FILES["photo"]["name"]);
$sourdeFile = $_FILES["photo"]["tmp_name"];
if(move_uploaded_file($sourdeFile,$destFile)){
echo "File has been uploaded";
$photo = $destFile;
}else{
echo $_FILES['photo']['error'];
$photo = "images/default.png";
}
When I upload photos they successfully uploaded into folder but the problem is its path recorded as follow :
uploads42141402_1866830986743601_8538143552767524864_n.jpg
But to view photos in a page there should be next to uploads. So I tried to change my code as follow.
$folder = "uploads";
But it generates this error
Can anyone say how to fix this ?
php file file-upload
php file file-upload
edited Nov 15 '18 at 8:33
octano
208415
208415
asked Nov 15 '18 at 7:51
Nipun TharukshaNipun Tharuksha
62
62
You have the wrong slash should be /
– rpm192
Nov 15 '18 at 8:06
i did it too.But still same error
– Nipun Tharuksha
Nov 15 '18 at 8:07
have you given read-write permission to the upload folder? also, check the uploads folder should be inside carsale/controller folder
– Sayed Mohd Ali
Nov 15 '18 at 8:34
i did it too.Moved the folder into controller folder and change.but error is till same
– Nipun Tharuksha
Nov 15 '18 at 9:43
add a comment |
You have the wrong slash should be /
– rpm192
Nov 15 '18 at 8:06
i did it too.But still same error
– Nipun Tharuksha
Nov 15 '18 at 8:07
have you given read-write permission to the upload folder? also, check the uploads folder should be inside carsale/controller folder
– Sayed Mohd Ali
Nov 15 '18 at 8:34
i did it too.Moved the folder into controller folder and change.but error is till same
– Nipun Tharuksha
Nov 15 '18 at 9:43
You have the wrong slash should be /
– rpm192
Nov 15 '18 at 8:06
You have the wrong slash should be /
– rpm192
Nov 15 '18 at 8:06
i did it too.But still same error
– Nipun Tharuksha
Nov 15 '18 at 8:07
i did it too.But still same error
– Nipun Tharuksha
Nov 15 '18 at 8:07
have you given read-write permission to the upload folder? also, check the uploads folder should be inside carsale/controller folder
– Sayed Mohd Ali
Nov 15 '18 at 8:34
have you given read-write permission to the upload folder? also, check the uploads folder should be inside carsale/controller folder
– Sayed Mohd Ali
Nov 15 '18 at 8:34
i did it too.Moved the folder into controller folder and change.but error is till same
– Nipun Tharuksha
Nov 15 '18 at 9:43
i did it too.Moved the folder into controller folder and change.but error is till same
– Nipun Tharuksha
Nov 15 '18 at 9:43
add a comment |
2 Answers
2
active
oldest
votes
How about
$folder ="uploads/";
I've tried and it works. Maybe $folder ="uploads" . DIRECTORY_SEPARATOR;
will better than "/".
no it dosent work
– Nipun Tharuksha
Nov 15 '18 at 8:05
Ahhh, I got why. How about this link
– Van Tho
Nov 15 '18 at 8:18
add a comment |
For the error its looks uploads folder is not there or it not have permission
create a upload folder or try with absolute path
you can make use of dirname(__FILE__) or $_SERVER['DOCUMENT_ROOT']
for creating dynamic path
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53314660%2fphp-file-uploading-cannot-retrieve-the-path%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
How about
$folder ="uploads/";
I've tried and it works. Maybe $folder ="uploads" . DIRECTORY_SEPARATOR;
will better than "/".
no it dosent work
– Nipun Tharuksha
Nov 15 '18 at 8:05
Ahhh, I got why. How about this link
– Van Tho
Nov 15 '18 at 8:18
add a comment |
How about
$folder ="uploads/";
I've tried and it works. Maybe $folder ="uploads" . DIRECTORY_SEPARATOR;
will better than "/".
no it dosent work
– Nipun Tharuksha
Nov 15 '18 at 8:05
Ahhh, I got why. How about this link
– Van Tho
Nov 15 '18 at 8:18
add a comment |
How about
$folder ="uploads/";
I've tried and it works. Maybe $folder ="uploads" . DIRECTORY_SEPARATOR;
will better than "/".
How about
$folder ="uploads/";
I've tried and it works. Maybe $folder ="uploads" . DIRECTORY_SEPARATOR;
will better than "/".
edited Nov 15 '18 at 8:05
answered Nov 15 '18 at 8:02
Van ThoVan Tho
846
846
no it dosent work
– Nipun Tharuksha
Nov 15 '18 at 8:05
Ahhh, I got why. How about this link
– Van Tho
Nov 15 '18 at 8:18
add a comment |
no it dosent work
– Nipun Tharuksha
Nov 15 '18 at 8:05
Ahhh, I got why. How about this link
– Van Tho
Nov 15 '18 at 8:18
no it dosent work
– Nipun Tharuksha
Nov 15 '18 at 8:05
no it dosent work
– Nipun Tharuksha
Nov 15 '18 at 8:05
Ahhh, I got why. How about this link
– Van Tho
Nov 15 '18 at 8:18
Ahhh, I got why. How about this link
– Van Tho
Nov 15 '18 at 8:18
add a comment |
For the error its looks uploads folder is not there or it not have permission
create a upload folder or try with absolute path
you can make use of dirname(__FILE__) or $_SERVER['DOCUMENT_ROOT']
for creating dynamic path
add a comment |
For the error its looks uploads folder is not there or it not have permission
create a upload folder or try with absolute path
you can make use of dirname(__FILE__) or $_SERVER['DOCUMENT_ROOT']
for creating dynamic path
add a comment |
For the error its looks uploads folder is not there or it not have permission
create a upload folder or try with absolute path
you can make use of dirname(__FILE__) or $_SERVER['DOCUMENT_ROOT']
for creating dynamic path
For the error its looks uploads folder is not there or it not have permission
create a upload folder or try with absolute path
you can make use of dirname(__FILE__) or $_SERVER['DOCUMENT_ROOT']
for creating dynamic path
edited Nov 15 '18 at 10:43
answered Nov 15 '18 at 10:35
Mahesh HegdeMahesh Hegde
54859
54859
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53314660%2fphp-file-uploading-cannot-retrieve-the-path%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
You have the wrong slash should be /
– rpm192
Nov 15 '18 at 8:06
i did it too.But still same error
– Nipun Tharuksha
Nov 15 '18 at 8:07
have you given read-write permission to the upload folder? also, check the uploads folder should be inside carsale/controller folder
– Sayed Mohd Ali
Nov 15 '18 at 8:34
i did it too.Moved the folder into controller folder and change.but error is till same
– Nipun Tharuksha
Nov 15 '18 at 9:43