mkdir() throws warning message - php

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.

Related

mkdir(): Not a directory PHP

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.

include_path won't work on PhpStorm

I have a construct function where I am using include_path, the function looks like this :
public function __construct()
{
$url = $this->parseUrl();
if(file_exists('application\controllers'.$url[0].'.php')){
$this->controller=$url[0];
unset($url[0]);
}
require_once 'application\controllers'.$this->controller.'.php';
echo $this->controller;
}
Unfortunately, when I try to load an existing controller url like this one http://localhost/project/public_html/home I get the following error :
Warning: require_once(application\controllers home.php): failed to open stream: No such file or directory in C:\xampp\htdocs\project\application\core\App.php on line 24
Fatal error: require_once(): Failed opening required 'application\controllers home.php' (include_path='C:\xampp\php\PEAR') in C:\xampp\htdocs\project\application\core\App.php on line 24
I followed the documentation and I included the paths :
C:\xampp\htdocs\project\application
and
C:\xampp\htdocs\project\application\controllers
but I am still getting the error and I am just clueless why... can someone help me?
But you have a space in the path...is that normal?
Can you try with 'application\controllers' (without space there) please?
And controllershome.php is the name of file, or controllers/home.php?

Warning: move_uploaded_file(): The second argument to copy() function

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).

Renaming a file results in 'No such file or directory'

I've been trying to rename an image file using php using this code.
$user_id = $_POST[user_id];
$old_image_name = $_POST[old_image_name];
$image_name = $_POST[image_name];
rename('/_img/user_memes/large/user_'.$user_id.'/'.$old_image_name.'', '/_img/user_memes/large/user_'.$user_id.'/'.$old_image_name.'');
The error I'm getting is-
"Warning: rename(/_img/user_memes/large/user_2/1524957_717357634955838_1917151587_n.jpg,/_img/user_memes/large/user_2/1524957_717357634955838_1917151587_n.jpg) [function.rename]: No such file or directory in /var/sites/o/oddmeme.com/public_html/_process/post_single_meme_edit.php on line 8"
The image is definitely there. I've tried removing the / at the start and trying a few different version but nothing has worked.
I've also set permission to 777 so that shouldn't be a problem.
First of all, you have an error in your code:
You are using twice the same path in your function with $old_image_name...
Fix that and tell us if it's working.

Expalanation for errors in the below code

if(!is_dir($dir_path))
{
$mk_dir=mkdir($dir_path, 0777);
$ch_mod=chmod($dir_path, 0777);
}
In the above code I am getting errors like below:
Warning: mkdir() [function.mkdir0]: No such file or directory in E:\salaahakardb\New Folder\xampp\htdocs\extramarks2\jnrcontent\fillblanks\form_vars.php on line 66
Warning: chmod() [function.chmod0]: No such file or directory in E:\salaahakardb\New Folder\xampp\htdocs\extramarks2\jnrcontent\fillblanks\form_vars.php on line 67
Please explain
The parent directory of the directory you're trying to create probably doesn't exist.
One way could be to create it recursively:
mkdir($dir_path, 0777, true);
Check http://php.net/manual/en/function.mkdir.php for further info.
Also you can get rid of that chmod() since you are already setting permissions while mkdir()'ing.
is_dir function returns false, if passed parameter is file - it's your situation.
try file_exists function

Categories