I'm creating a path with codeigniter on PHP and I'm getting this php error :
A PHP Error was encountered
Severity: Warning
Message: mkdir(): Not a directory
Filename: devotee/acc.devotee.php
Line Number: 81
Here is the line of code that php is complaining about
// Set cache settings
$this->_cache_path = $this->EE->config->item('devotee_monitor_cachepath') ? $this->EE->config->item('devotee_monitor_cachepath') : APPPATH . 'cache/devotee/';
$this->_cache_time = 60 * 60; // 1 hour
// Create cache folder if it doesn't exist
if(! is_dir($this->_cache_path))
{
mkdir($this->_cache_path, DIR_WRITE_MODE);
}
Also, in addition to checking what $this->_cache_path is resolving to as Bassem Samir mentions, make sure that your param to mkdir() does not have a trailing slash. For example,
mkdir("some_dir");
... Works
Whereas
mkdir("some_dir/");
... Doesn't work.
In other words, mkdir() will expect something to follow the slash: the sub folder. If not present, you'll get an error.
You should check the content of $this->_cache_path. It can be empty so mkdir throws warning message.
Related
I'm working on a file upload method. But i suddenly start to get the following error, The only thing I changed was the file name. I reverted it back, but the error still persists.
Does anyone know how to solve this?
The error message is:
Warning: move_uploaded_file(): The second argument to copy()
function cannot be a directory in
/hermes/bosnaweb14a/b1717/ipg.plantationkeyartcorn/kittyrescuetnr/docs/upload.php
on line 13
Warning: move_uploaded_file(): Unable to move '/tmp/phpJki8OC' to '/' in
/hermes/bosnaweb14a/b1717/ipg.plantationkeyartcorn/kittyrescuetnr/docs/upload.php
on line 13
Fail
my php looks like this
<?php
$file_upload="true";
$file_up_size=$_FILES['file_up'][size];
$file_destination=$REQUEST['file_type'];
$file_new_name=$REQUEST['file_name'];
$file_name=$_FILES[file_up][name];
**$add="$file_destination/$file_new_name"; // the path with the file name where the file will be stored**
if($file_upload=="true"){
if(move_uploaded_file ($_FILES[file_up][tmp_name], $add)){
echo print_r($file_new_name);
}else{echo "Fail";}
}else{
echo $msg;
}
?>
Well, since you are using superglobal array $_REQUEST incorrectly (notice the underscore in the name), your $add variable evaluates to just a slash. Which is a root directory.
Hence the errors - it is a directory after all and your script probably don't have write access to it anyway (which is a good thing).
I have 3 php pages where details is supposed to be inserted to db in final php.. I am geetting these warnings below however data is inserted. I know these warning can be turned of by error reporting but doesnt look good to me go for that..
Warning: copy(): The first argument to copy() function cannot be a directory in /home/opterfhb/public_html/quest4home.com/search/add_edit_property_finish.php on line 301
Warning: unlink(tmp_imgs/tmp_1011/..): Is a directory in /home/opterfhb/public_html/quest4home.com/search/add_edit_property_finish.php on line 302
Warning: copy(): The first argument to copy() function cannot be a directory in /home/opterfhb/public_html/quest4home.com/search/add_edit_property_finish.php on line 301
Warning: unlink(tmp_imgs/tmp_1011/.): Is a directory in /home/opterfhb/public_html/quest4home.com/search/add_edit_property_finish.php on line 302
I think I have defined it wrong way.. seeking help..
I am getting error on this section:
// Moveing temp images to property directory
if ($handle = opendir('tmp_imgs/tmp_'.$property_id)) {
while (false !== ($file = readdir($handle)))
{
//$file_ext = strtolower(substr($file, strrpos($file, '.') + 1));
copy('tmp_imgs/tmp_'.$property_id.'/'.$file, 'property_images/img_'.$property_id.'/'.$file);
unlink('tmp_imgs/tmp_'.$property_id.'/'.$file);
}
closedir($handle);
}
The error is clear: you cannot use that function to copy directories. However, you may not be aware that you're even trying to do this in the first place.
There are magical "files" in each directory which are themselves directories (. and ..), so if you're iterating over a directory and copying everything in it, you need to explicitly skip those two.
I seem to get this error on my local server when the site is loaded for the first time e.g. in the morning. Once I do a refresh it's gone...
I'm using silverstripe 3.1.
Is there a way to prevent this locally or is this a bug?
Warning: mkdir(): File exists in /framework/core/manifest/ManifestCache.php on line 19
Looks like line 19 is trying to create a TEMP folder but it already exists...
function __construct($name) {
$this->folder = TEMP_FOLDER.'/'.$name;
if (!is_dir($this->folder)) mkdir($this->folder);
}
Should that function check if the folder exists first e.g.
if (!is_dir($this->folder) || !file_exists($this->folder)) mkdir($this->folder);
Seems that there exists a file with the same name as the directory. That's why is_dir() returns false but mkdir() fails because the file exists.
You can change this to:
if (!file_exists($this->folder)) mkdir($this->folder);
This should work so far.
However it is necessary to mention that such file existence tests are vulnerable against race conditions by design. That's why you need to additionally check the return value of mkdir():
if (!file_exists($this->folder)) {
if(#mkdir($this->folder) === FALSE) {
throw new Exception('failed to create ' . $this->folder);
}
}
This may not being required if you (or the framework) has registered a global error handler which turns warning into exceptions, because mkdir() will throw a warning on errors.
What's the error in here?
<?php
define('TMP_FOLDER','temp');
$temp_dir = $this->dir['root'].$this->config['sep'].TMP_FOLDER;
//$temp_dir = C:\xampp\htdocs\xxx\temp
//$this->dir['root'] = C:\xampp\htdocs\xxx
if(!file_exists($temp_dir) && !is_dir($temp_dir)){
chdir('../');
mkdir(TMP_FOLDER, 0744);
}
?>
This throws a warning like:-
Warning: mkdir(): File exists in C:\xampp\htdocs\xxx\yyy\display.php on line 49
I think this is an easy job. But, I can't understand what's this?
remove below line and try
chdir('../');
Found it, I removed the line
chdir('../');
changing the directory, directed to c:\xampp\htdocs. Removing this solved the problem.
I am trying to upload file on ftp.
here is my code
$jname= "Accounts of Biotechnology Research";
if (!is_dir('/Trade/upload/ '.$jname)) {
mkdir('/Trade/upload/ '.$jname); // line 63
}
move_uploaded_file($_FILES["submission_file"]["tmp_name"], "/Trade/upload/$jname/" . $dup_name ); // line 67
Trade is a folder inside public_html folder.
When i am uploading a file it gives me a warning like,
Warning: mkdir() [function.mkdir]: No such file or directory in /home/my_username/public_html/Trade/upload.php on line 63
Warning: move_uploaded_file(/Trade/upload/Accounts of Biotechnology Research/76164762-sm.pdf) [function.move-uploaded-file]: failed to open stream: No such file or directory in /home/my_username/public_html/Trade/upload.php on line 67
Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phphZXp0O' to '/Trade/upload/Accounts of Biotechnology Research/76164762-sm.pdf' in /home/my_username/public_html/Trade/upload.php on line 67
First:
You have a space here mkdir('/Trade/upload/ '.$jname);. Suppose you should have mkdir('/Trade/upload/'.$jname); (same for is_dir)
Second:
Ensure that you can write into Trade/upload directory.
Third (and I suppose that is the real problem):
It looks like you are trying to upload into a directory with full path:
/home/my_username/public_html/Trade/upload/, but your code will try to create a directory with full path:
/Trade/upload/.
You need to change
if (!is_dir('/Trade/upload/ '.$jname)) {
mkdir('/Trade/upload/ '.$jname); // line 63
}
to
if (!is_dir('upload/'.$jname)) {
mkdir('upload/'.$jname); // line 63 (or maybe there should be Trade/upload, but suppose current working dir will be /home/my_username/public_html/Trade, so only upload/)
}
Another option is to force mkdir to create directories recursively:
mkdir('/Trade/upload/'.$jname, 0755, true);
But in that case, files will be uploaded into /Trade/upload/... instead of /home/my_username/public_html/Trade/upload/...
There are two things you should be aware of based on the error messages you received. I'm guessing /Trade isn't the root path on your machine since it's clear in the error that your actual path is /home/my_username/public_html/Trade/, so the first adjustment should be
$root_path = "/home/my_username/public_html/Trade/upload/";
The second adjustment I'd suggest is that you avoid pathnames with space in them:
$jname= "Accounts of Biotechnology Research"; //could be changed to
$jname= "Accounts_of_Biotechnology_Research"; //$jname = str_replace(" ","-",$jname) OR
$jname= "Accounts-of-Biotechnology-Research"; //$jname = str_replace(" ","-",$jname)
Finally take note of the space character on the following lines, they affect you final result:
if (!is_dir('/Trade/upload/ '.$jname)) { //AND
mkdir('/Trade/upload/ '.$jname);
}
Note the [space] between upload/ '.$jname in both strings.