FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » mkdir no such file or directory
Show: Today's Messages :: Unread Messages :: Show Polls :: Message Navigator
| Subscribe to topic | Bookmark topic 
Switch to threaded view of this topic Create a new topic Submit Reply
mkdir no such file or directory [message #181387] Tue, 14 May 2013 23:04 Go to next message
Bhushan N.N is currently offline  Bhushan N.N
Messages: 7
Registered: May 2013
Karma: 0
Junior Member
add to buddy list
ignore all messages by this user
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] Tue, 14 May 2013 23:06 Go to previous messageGo to next message
Bhushan N.N is currently offline  Bhushan N.N
Messages: 7
Registered: May 2013
Karma: 0
Junior Member
add to buddy list
ignore all messages by this user
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 00:34 Go to previous messageGo to next message
J.O. Aho is currently offline  J.O. Aho
Messages: 194
Registered: September 2010
Karma: 0
Senior Member
add to buddy list
ignore all messages by this user
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 00:37 Go to previous messageGo to next message
Richard Yates is currently offline  Richard Yates
Messages: 86
Registered: September 2013
Karma: 0
Member
add to buddy list
ignore all messages by this user
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 #181392 is a reply to message #181388] Wed, 15 May 2013 00:39 Go to previous messageGo to next message
Martin Leese is currently offline  Martin Leese
Messages: 23
Registered: June 2012
Karma: 0
Junior Member
add to buddy list
ignore all messages by this user
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.");
> }

When I modified your error line to:
echo("Oops, error creating directory \"$filelocation\".");

I got the output:
Oops, error creating directory "/uploads//1368592056".

Note the double "/" in the directory name.

Also, check you have permission to create a
directory in your root directory.

--
Regards,
Martin Leese
E-mail: please(at)see(dot)Web(dot)for(dot)e-mail(dot)INVALID
Web: http://members.tripod.com/martin_leese/
Re: mkdir no such file or directory [message #181395 is a reply to message #181388] Wed, 15 May 2013 06:05 Go to previous messageGo to next message
Arno Welzel is currently offline  Arno Welzel
Messages: 317
Registered: October 2011
Karma: 0
Senior Member
add to buddy list
ignore all messages by this user
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 06:23 Go to previous messageGo to next message
The Natural Philosoph is currently offline  The Natural Philosoph
Messages: 993
Registered: September 2010
Karma: 0
Senior Member
add to buddy list
ignore all messages by this user
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 08:38 Go to previous messageGo to next message
Denis McMahon is currently offline  Denis McMahon
Messages: 634
Registered: September 2010
Karma: 0
Senior Member
add to buddy list
ignore all messages by this user
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 09:51 Go to previous messageGo to next message
Robert Heller is currently offline  Robert Heller
Messages: 60
Registered: December 2010
Karma: 0
Member
add to buddy list
ignore all messages by this user
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 #181408 is a reply to message #181406] Wed, 15 May 2013 11:19 Go to previous messageGo to next message
Bhushan N.N is currently offline  Bhushan N.N
Messages: 7
Registered: May 2013
Karma: 0
Junior Member
add to buddy list
ignore all messages by this user
Hi Robert,

I want the uploads directory where I am hosting the website files.
Re: mkdir no such file or directory [message #181409 is a reply to message #181408] Wed, 15 May 2013 11:20 Go to previous messageGo to next message
Bhushan N.N is currently offline  Bhushan N.N
Messages: 7
Registered: May 2013
Karma: 0
Junior Member
add to buddy list
ignore all messages by this user
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
Re: mkdir no such file or directory [message #181410 is a reply to message #181409] Wed, 15 May 2013 12:37 Go to previous messageGo to next message
Thomas 'PointedEars'  is currently offline  Thomas 'PointedEars'
Messages: 701
Registered: October 2010
Karma: 0
Senior Member
add to buddy list
ignore all messages by this user
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 14:44 Go to previous messageGo to next message
Robert Heller is currently offline  Robert Heller
Messages: 60
Registered: December 2010
Karma: 0
Member
add to buddy list
ignore all messages by this user
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 15:31 Go to previous messageGo to next message
Thomas 'PointedEars'  is currently offline  Thomas 'PointedEars'
Messages: 701
Registered: October 2010
Karma: 0
Senior Member
add to buddy list
ignore all messages by this user
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 19:20 Go to previous messageGo to next message
Bhushan N.N is currently offline  Bhushan N.N
Messages: 7
Registered: May 2013
Karma: 0
Junior Member
add to buddy list
ignore all messages by this user
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
Re: mkdir no such file or directory [message #181432 is a reply to message #181429] Wed, 15 May 2013 19:55 Go to previous message
Denis McMahon is currently offline  Denis McMahon
Messages: 634
Registered: September 2010
Karma: 0
Senior Member
add to buddy list
ignore all messages by this user
> Please learn how to post properly? Don't really know what you mean.
> Thanks a lot anyway for your help. Appreciate it.

He means that your reply should go *DOWN HERE*, _underneath the quoted
text_
Quick Reply
Formatting Tools:   
  Switch to threaded view of this topic Create a new topic
Previous Topic: Booleans compared to strings
Next Topic: isset not working with select
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Sun Dec 17 01:23:03 EST 2017

Total time taken to generate the page: 0.00894 seconds