mkdir no such file or directory [message #181387] |
Wed, 15 May 2013 03:04 |
Bhushan N.N
Messages: 7 Registered: May 2013
Karma: 0
|
Junior Member |
|
|
I want to create a directory using mkdir. But I get "No such file or directory" error.
Below is the code I am using.
$filelocation = "/uploads/" . "/" . time();
Can some one please tell me what I am doing wrong?
I also tried manually creating the uploads folder. Still the same error. Any help will be much appreciated.
|
|
|
Re: mkdir no such file or directory [message #181388 is a reply to message #181387] |
Wed, 15 May 2013 03:06 |
Bhushan N.N
Messages: 7 Registered: May 2013
Karma: 0
|
Junior Member |
|
|
Here is my code again
$filelocation = "/uploads/" . "/" . time();
if (mkdir($filelocation,0777,true))
{
echo("Thank you for uploading the file.");
}
else
{
echo("Oops error uploading file.");
}
On Tuesday, 14 May 2013 21:04:27 UTC-6, Bhushan N.N wrote:
> I want to create a directory using mkdir. But I get "No such file or directory" error.
>
>
>
> Below is the code I am using.
>
>
>
> $filelocation = "/uploads/" . "/" . time();
>
>
>
> Can some one please tell me what I am doing wrong?
>
>
>
> I also tried manually creating the uploads folder. Still the same error. Any help will be much appreciated.
|
|
|
Re: mkdir no such file or directory [message #181390 is a reply to message #181388] |
Wed, 15 May 2013 04:34 |
J.O. Aho
Messages: 194 Registered: September 2010
Karma: 0
|
Senior Member |
|
|
On 15/05/13 05:06, Bhushan N.N wrote:
NOTE: Don't top post, reply inline. If not replying to the whole post,
then remove those parts you don't reply to.
>> I want to create a directory using mkdir. But I get "No such file or directory" error.
mkdir() will only give true or false depending on if it can create the
directory or not.
>> Below is the code I am using.
>> $filelocation = "/uploads/" . "/" . time();
Usually the user as who the process is run as (web server user or a
normal user) will not have the right to make a directory in the root
file system (path: /), but we assume you have full control of the web
server and can create the directory /uploads and have already made it,
then you need to allow the web server/normal user as whom the php script
is run as to have rwx on that directory.
>> Can some one please tell me what I am doing wrong?
>> I also tried manually creating the uploads folder. Still the same error. Any help will be much appreciated.
>
> Here is my code again
>
> $filelocation = "/uploads/" . "/" . time();
> if (mkdir($filelocation,0777,true))
> {
> echo("Thank you for uploading the file.");
> }
> else
> {
> echo("Oops error uploading file.");
> }
$path = "/uploads";
$dir = time();
if(file_exists($path)) {
if(file_exists($path."/".$dir)) {
echo "directory {$path}/{$dir} already exists";
} else {
if(mkdir($path."/".$dir,0777,true)) {
echo "Created {$path}/{$dir}";
} else {
echo "Can't create {$path}/{$dir}";
}
}
} else {
echo "{$path} is missing";
}
This is a simple check with a bad way of echoing out results, this don't
check if the file really is a directory, is_dir() will tell you that if
you want to make the check more complete, I suggest you look at
Exceptions instead of just echo everything.
--
//Aho
|
|
|
Re: mkdir no such file or directory [message #181391 is a reply to message #181388] |
Wed, 15 May 2013 04:37 |
Richard Yates
Messages: 86 Registered: September 2013
Karma: 0
|
Member |
|
|
On Tue, 14 May 2013 20:06:19 -0700 (PDT), "Bhushan N.N"
<bhushan154(at)gmail(dot)com> wrote:
> Here is my code again
>
> $filelocation = "/uploads/" . "/" . time();
> if (mkdir($filelocation,0777,true))
> {
> echo("Thank you for uploading the file.");
> }
> else
> {
> echo("Oops error uploading file.");
> }
>
> On Tuesday, 14 May 2013 21:04:27 UTC-6, Bhushan N.N wrote:
>> I want to create a directory using mkdir. But I get "No such file or directory" error.
>>
>>
>>
>> Below is the code I am using.
>>
>>
>>
>> $filelocation = "/uploads/" . "/" . time();
>>
>>
>>
>> Can some one please tell me what I am doing wrong?
>>
>>
>>
>> I also tried manually creating the uploads folder. Still the same error. Any help will be much appreciated.
I don't know anuything about mkdir, but isn't:
"/uploads/" . "/" . time() the same as:
"/uploads//".time();
Are those two forward slashes causing the error?
|
|
|
|
Re: mkdir no such file or directory [message #181395 is a reply to message #181388] |
Wed, 15 May 2013 10:05 |
Arno Welzel
Messages: 317 Registered: October 2011
Karma: 0
|
Senior Member |
|
|
Am 15.05.2013 05:06, schrieb Bhushan N.N:
> Here is my code again
>
> $filelocation = "/uploads/" . "/" . time();
> if (mkdir($filelocation,0777,true))
> {
> echo("Thank you for uploading the file.");
> }
> else
> {
> echo("Oops error uploading file.");
> }
1) Look carefully: "/uploads/" . "/" will result in "uploads//"
2) Does /uploads exist? It seems you miss the whole path the the root
directory of the webserver (/var/www/....) or you did not understand the
difference between the root URL in your browser and the physical path on
the machine where the script runs.
I assume you need a full path and not just "/uploads" and you have to
make sure, that the user which is used to execute PHP has the right
access rights within the given path.
--
Arno Welzel
http://arnowelzel.de
http://de-rec-fahrrad.de
|
|
|
Re: mkdir no such file or directory [message #181398 is a reply to message #181388] |
Wed, 15 May 2013 10:23 |
The Natural Philosoph
Messages: 993 Registered: September 2010
Karma: 0
|
Senior Member |
|
|
On 15/05/13 04:06, Bhushan N.N wrote:
> Here is my code again
>
> $filelocation = "/uploads/" . "/" . time();
that looks to me like "/uploads//12345678901234567890"
which probably isn't a reason for failure with the double slash, but is
ugly.
However, do you have permission to create a directory in the root file
system of your computer?
Try removing the leading slash to its relative to wherever PHP is
operating, or better still use the PHP defined constant that tells you
where the root file system is, as a prefix.
--
Ineptocracy
(in-ep-toc’-ra-cy) – a system of government where the least capable to lead are elected by the least capable of producing, and where the members of society least likely to sustain themselves or succeed, are rewarded with goods and services paid for by the confiscated wealth of a diminishing number of producers.
|
|
|
Re: mkdir no such file or directory [message #181403 is a reply to message #181388] |
Wed, 15 May 2013 12:38 |
Denis McMahon
Messages: 634 Registered: September 2010
Karma: 0
|
Senior Member |
|
|
On Tue, 14 May 2013 20:06:19 -0700, Bhushan N.N wrote:
> Here is my code again
>
> $filelocation = "/uploads/" . "/" . time();
> if (mkdir($filelocation,0777,true))
> {
> echo("Thank you for uploading the file.");
> }
> else {
> echo("Oops error uploading file.");
> }
Does /uploads exist on your system?
If /uploads does exist, has the webserver process got sufficient access
to create subdirs in it?
If /uploads does not exist, has the webserver process got sufficient
access to create it?
Given that creating anything at / usually requires root level access, and
it's generally not recommended to run web servers as root, I suspect
access rights might be your problem.
--
Denis McMahon, denismfmcmahon(at)gmail(dot)com
|
|
|
Re: mkdir no such file or directory [message #181406 is a reply to message #181403] |
Wed, 15 May 2013 13:51 |
Robert Heller
Messages: 60 Registered: December 2010
Karma: 0
|
Member |
|
|
At Wed, 15 May 2013 12:38:27 +0000 (UTC) Denis McMahon <denismfmcmahon(at)gmail(dot)com> wrote:
>
> On Tue, 14 May 2013 20:06:19 -0700, Bhushan N.N wrote:
>
>> Here is my code again
>>
>> $filelocation = "/uploads/" . "/" . time();
>> if (mkdir($filelocation,0777,true))
>> {
>> echo("Thank you for uploading the file.");
>> }
>> else {
>> echo("Oops error uploading file.");
>> }
>
> Does /uploads exist on your system?
> If /uploads does exist, has the webserver process got sufficient access
> to create subdirs in it?
> If /uploads does not exist, has the webserver process got sufficient
> access to create it?
>
> Given that creating anything at / usually requires root level access, and
> it's generally not recommended to run web servers as root, I suspect
> access rights might be your problem.
And: maybe the OP *really* means something like:
$filelocation = dirname(__FILE__) . "/uploads/" . "/" . time();
That is, he might really want uploads to be *relative* to files on the
website, rather than a absolute place on the server's file system. (The
'dirname(__FILE__)' is just an example, there might be other possibilities.)
>
--
Robert Heller -- 978-544-6933 / heller(at)deepsoft(dot)com
Deepwoods Software -- http://www.deepsoft.com/
() ascii ribbon campaign -- against html e-mail
/\ www.asciiribbon.org -- against proprietary attachments
|
|
|
|
|
Re: mkdir no such file or directory [message #181410 is a reply to message #181409] |
Wed, 15 May 2013 16:37 |
Thomas 'PointedEars'
Messages: 701 Registered: October 2010
Karma: 0
|
Senior Member |
|
|
Bhushan N.N wrote:
> ie, if my website is called example, the structure will be
>
> example
> index.php
> upload.php
> search.php
> uploads
> 12209214
> somefile.txt
> 31231203
> otherfile.txt
> about.php
> contact.php
Please learn how to post properly on Usenet. Avoid Google Groups in favor
of a locally installed newsreader application if possible.
The problem here is that you are falsely assuming that “/” refers to the
document root. Instead, it refers to the *filesystem* root, where you/the
Web server SHOULD NOT have write access. As “uploads” is a directory on the
same level as upload.php, it is probably easiest for you just to omit the
leading “/”.
However, it would be safest to refer to the document root explicitly, like
$_SERVER['DOCUMENT_ROOT'] . '/uploads/' . $value
(As you can see, it does not make sense to concatenate '/uploads' . '/' when
you can just write '/uploads/'.)
It also does not make a lot of sense to create a directory for every second
of upload since epoch, using time(). If you need to group uploads by date
for quick access, I suggest you use year/month/date instead. That said, you
can rather easily filter an array of file information, so unless there is a
chance that on different times people would upload files with the *same*
name where they do *not* want to overwrite the old version, you do not need
that directory structure.
However, in a multi-user application another piece is missing in any case:
You need a way to differentiate between the files of users or one user could
overwrite the file of another. Using time() _cannot_ prevent that from
happening, because there is the possibility of concurrent access.
PointedEars
--
Anyone who slaps a 'this page is best viewed with Browser X' label on
a Web page appears to be yearning for the bad old days, before the Web,
when you had very little chance of reading a document written on another
computer, another word processor, or another network. -- Tim Berners-Lee
|
|
|
Re: mkdir no such file or directory [message #181412 is a reply to message #181409] |
Wed, 15 May 2013 18:44 |
Robert Heller
Messages: 60 Registered: December 2010
Karma: 0
|
Member |
|
|
At Wed, 15 May 2013 08:20:45 -0700 (PDT) "Bhushan N.N" <bhushan154(at)gmail(dot)com> wrote:
>
> ie, if my website is called example, the structure will be
>
> example
> index.php
> upload.php
> search.php
> uploads
> 12209214
> somefile.txt
> 31231203
> otherfile.txt
> about.php
> contact.php
>
That means you don't want "/uploads"! If the mkdir code is in upload.php,
then you really do want:
$directory = dirname(__FILE__) . "/uploads/" . time();
--
Robert Heller -- 978-544-6933 / heller(at)deepsoft(dot)com
Deepwoods Software -- http://www.deepsoft.com/
() ascii ribbon campaign -- against html e-mail
/\ www.asciiribbon.org -- against proprietary attachments
|
|
|
Re: mkdir no such file or directory [message #181414 is a reply to message #181412] |
Wed, 15 May 2013 19:31 |
Thomas 'PointedEars'
Messages: 701 Registered: October 2010
Karma: 0
|
Senior Member |
|
|
Robert Heller wrote:
> "Bhushan N.N" wrote:
>> ie, if my website is called example, the structure will be
>>
>> example
>> index.php
>> upload.php
>> search.php
>> uploads
>> 12209214
>> somefile.txt
>> 31231203
>> otherfile.txt
>> about.php
>> contact.php
>
> That means you don't want "/uploads"! If the mkdir code is in upload.php,
> then you really do want:
>
> $directory = dirname(__FILE__) . "/uploads/" . time();
From PHP 5.3 on they may want to use
$directory = __DIR__ . "/uploads/" . time();
instead. However, see my other answer as to why either approach is not a
good idea.
PointedEars
--
Anyone who slaps a 'this page is best viewed with Browser X' label on
a Web page appears to be yearning for the bad old days, before the Web,
when you had very little chance of reading a document written on another
computer, another word processor, or another network. -- Tim Berners-Lee
|
|
|
Re: mkdir no such file or directory [message #181429 is a reply to message #181410] |
Wed, 15 May 2013 23:20 |
Bhushan N.N
Messages: 7 Registered: May 2013
Karma: 0
|
Junior Member |
|
|
Thomas,
Thanks for your feedback.
I just put that uploads/time format as an example. In the real application I will be using
uploads/<username>/time format
Please learn how to post properly? Don't really know what you mean. Thanks a lot anyway for your help. Appreciate it.
Thank you
Bhushan
On Wednesday, 15 May 2013 10:37:15 UTC-6, Thomas 'PointedEars' Lahn wrote:
> Bhushan N.N wrote:
>
>
>
>> ie, if my website is called example, the structure will be
>
>>
>
>> example
>
>> index.php
>
>> upload.php
>
>> search.php
>
>> uploads
>
>> 12209214
>
>> somefile.txt
>
>> 31231203
>
>> otherfile.txt
>
>> about.php
>
>> contact.php
>
>
>
> Please learn how to post properly on Usenet. Avoid Google Groups in favor
>
> of a locally installed newsreader application if possible.
>
>
>
> The problem here is that you are falsely assuming that “/” refers to the
>
> document root. Instead, it refers to the *filesystem* root, where you/the
>
> Web server SHOULD NOT have write access. As “uploads” is a directory on the
>
> same level as upload.php, it is probably easiest for you just to omit the
>
> leading “/”.
>
>
>
> However, it would be safest to refer to the document root explicitly, like
>
>
>
> $_SERVER['DOCUMENT_ROOT'] . '/uploads/' . $value
>
>
>
> (As you can see, it does not make sense to concatenate '/uploads' . '/' when
>
> you can just write '/uploads/'.)
>
>
>
> It also does not make a lot of sense to create a directory for every second
>
> of upload since epoch, using time(). If you need to group uploads by date
>
> for quick access, I suggest you use year/month/date instead. That said, you
>
> can rather easily filter an array of file information, so unless there is a
>
> chance that on different times people would upload files with the *same*
>
> name where they do *not* want to overwrite the old version, you do not need
>
> that directory structure.
>
>
>
> However, in a multi-user application another piece is missing in any case:
>
> You need a way to differentiate between the files of users or one user could
>
> overwrite the file of another. Using time() _cannot_ prevent that from
>
> happening, because there is the possibility of concurrent access.
>
>
>
>
>
> PointedEars
>
> --
>
> Anyone who slaps a 'this page is best viewed with Browser X' label on
>
> a Web page appears to be yearning for the bad old days, before the Web,
>
> when you had very little chance of reading a document written on another
>
> computer, another word processor, or another network. -- Tim Berners-Lee
|
|
|
|