Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.php > #9333 > unrolled thread

mkdir no such file or directory

Started by"Bhushan N.N" <bhushan154@gmail.com>
First post2013-05-14 20:04 -0700
Last post2013-05-15 21:31 +0200
Articles 16 — 9 participants

Back to article view | Back to comp.lang.php


Contents

  mkdir no such file or directory "Bhushan N.N" <bhushan154@gmail.com> - 2013-05-14 20:04 -0700
    Re: mkdir no such file or directory "Bhushan N.N" <bhushan154@gmail.com> - 2013-05-14 20:06 -0700
      Re: mkdir no such file or directory "J.O. Aho" <user@example.net> - 2013-05-15 06:34 +0200
      Re: mkdir no such file or directory Richard Yates <richard@yatesguitar.com> - 2013-05-14 21:37 -0700
      Re: mkdir no such file or directory Martin Leese <please@see.Web.for.e-mail.INVALID> - 2013-05-14 22:39 -0600
      Re: mkdir no such file or directory Arno Welzel <usenet@arnowelzel.de> - 2013-05-15 12:05 +0200
      Re: mkdir no such file or directory The Natural Philosopher <tnp@invalid.invalid> - 2013-05-15 11:23 +0100
      Re: mkdir no such file or directory Denis McMahon <denismfmcmahon@gmail.com> - 2013-05-15 12:38 +0000
        Re: mkdir no such file or directory Robert Heller <heller@deepsoft.com> - 2013-05-15 08:51 -0500
          Re: mkdir no such file or directory "Bhushan N.N" <bhushan154@gmail.com> - 2013-05-15 08:19 -0700
            Re: mkdir no such file or directory "Bhushan N.N" <bhushan154@gmail.com> - 2013-05-15 08:20 -0700
              Re: mkdir no such file or directory Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-05-15 18:37 +0200
                Re: mkdir no such file or directory "Bhushan N.N" <bhushan154@gmail.com> - 2013-05-15 16:20 -0700
                  Re: mkdir no such file or directory Denis McMahon <denismfmcmahon@gmail.com> - 2013-05-15 23:55 +0000
              Re: mkdir no such file or directory Robert Heller <heller@deepsoft.com> - 2013-05-15 13:44 -0500
                Re: mkdir no such file or directory Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-05-15 21:31 +0200

#9333 — mkdir no such file or directory

From"Bhushan N.N" <bhushan154@gmail.com>
Date2013-05-14 20:04 -0700
Subjectmkdir no such file or directory
Message-ID<a47b8f8a-1bd8-45c2-8edc-dd5fa2934203@googlegroups.com>
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.

[toc] | [next] | [standalone]


#9334

From"Bhushan N.N" <bhushan154@gmail.com>
Date2013-05-14 20:06 -0700
Message-ID<1d2ec34d-5532-4576-bcce-8c0cb77637ab@googlegroups.com>
In reply to#9333
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.

[toc] | [prev] | [next] | [standalone]


#9336

From"J.O. Aho" <user@example.net>
Date2013-05-15 06:34 +0200
Message-ID<avghj9F68pvU1@mid.individual.net>
In reply to#9334
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

[toc] | [prev] | [next] | [standalone]


#9337

FromRichard Yates <richard@yatesguitar.com>
Date2013-05-14 21:37 -0700
Message-ID<o446p8d1bhhj3p19pm48pvmu885h4vtuaa@4ax.com>
In reply to#9334
On Tue, 14 May 2013 20:06:19 -0700 (PDT), "Bhushan N.N"
<bhushan154@gmail.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?

[toc] | [prev] | [next] | [standalone]


#9338

FromMartin Leese <please@see.Web.for.e-mail.INVALID>
Date2013-05-14 22:39 -0600
Message-ID<kmv3be$bi1$1@dont-email.me>
In reply to#9334
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@see.Web.for.e-mail.INVALID
Web: http://members.tripod.com/martin_leese/

[toc] | [prev] | [next] | [standalone]


#9341

FromArno Welzel <usenet@arnowelzel.de>
Date2013-05-15 12:05 +0200
Message-ID<51935DED.4000704@arnowelzel.de>
In reply to#9334
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

[toc] | [prev] | [next] | [standalone]


#9344

FromThe Natural Philosopher <tnp@invalid.invalid>
Date2013-05-15 11:23 +0100
Message-ID<kmvnmq$of2$2@news.albasani.net>
In reply to#9334
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.

[toc] | [prev] | [next] | [standalone]


#9349

FromDenis McMahon <denismfmcmahon@gmail.com>
Date2013-05-15 12:38 +0000
Message-ID<kmvvk3$8so$1@dont-email.me>
In reply to#9334
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@gmail.com

[toc] | [prev] | [next] | [standalone]


#9352

FromRobert Heller <heller@deepsoft.com>
Date2013-05-15 08:51 -0500
Message-ID<TpSdnW030t12Dw7MnZ2dnUVZ_q2dnZ2d@giganews.com>
In reply to#9349
At Wed, 15 May 2013 12:38:27 +0000 (UTC) Denis McMahon <denismfmcmahon@gmail.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@deepsoft.com
Deepwoods Software        -- http://www.deepsoft.com/
()  ascii ribbon campaign -- against html e-mail
/\  www.asciiribbon.org   -- against proprietary attachments


 

[toc] | [prev] | [next] | [standalone]


#9354

From"Bhushan N.N" <bhushan154@gmail.com>
Date2013-05-15 08:19 -0700
Message-ID<6377e853-a93c-47d9-953b-5a53ea8d641a@googlegroups.com>
In reply to#9352
Hi Robert,

I want the uploads directory where I am hosting the website files.

[toc] | [prev] | [next] | [standalone]


#9355

From"Bhushan N.N" <bhushan154@gmail.com>
Date2013-05-15 08:20 -0700
Message-ID<a880675e-703c-4890-bd58-c41e9c76cfba@googlegroups.com>
In reply to#9354
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

[toc] | [prev] | [next] | [standalone]


#9356

FromThomas 'PointedEars' Lahn <PointedEars@web.de>
Date2013-05-15 18:37 +0200
Message-ID<7303141.T0OLTIN1oa@PointedEars.de>
In reply to#9355
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

[toc] | [prev] | [next] | [standalone]


#9375

From"Bhushan N.N" <bhushan154@gmail.com>
Date2013-05-15 16:20 -0700
Message-ID<b46ceca1-d917-47c3-9a2e-6d63b3cf976e@googlegroups.com>
In reply to#9356
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

[toc] | [prev] | [next] | [standalone]


#9378

FromDenis McMahon <denismfmcmahon@gmail.com>
Date2013-05-15 23:55 +0000
Message-ID<kn17af$8so$8@dont-email.me>
In reply to#9375
> 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_

[toc] | [prev] | [next] | [standalone]


#9358

FromRobert Heller <heller@deepsoft.com>
Date2013-05-15 13:44 -0500
Message-ID<L56dnaFJ-_MOSg7MnZ2dnUVZ_r-dnZ2d@giganews.com>
In reply to#9355
At Wed, 15 May 2013 08:20:45 -0700 (PDT) "Bhushan N.N" <bhushan154@gmail.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@deepsoft.com
Deepwoods Software        -- http://www.deepsoft.com/
()  ascii ribbon campaign -- against html e-mail
/\  www.asciiribbon.org   -- against proprietary attachments


                                                

[toc] | [prev] | [next] | [standalone]


#9360

FromThomas 'PointedEars' Lahn <PointedEars@web.de>
Date2013-05-15 21:31 +0200
Message-ID<6448731.fcIk2o3Qxo@PointedEars.de>
In reply to#9358
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

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.php


csiph-web