pls i need help am trying to use the mkdir for user profile pic upload and its not working ... but when i use it normally i.e ordinarilly for example when i created a new php page and used " mkdir("newdir") "it worked
<?php
if (isset($_FILES['profilepic'])) {
if (((@$_FILES["profilepic"]["type"]=="image/jpeg") ||
(@$_FILES["profilepic"]["type"]=="image/png") || (@$_FILES["profilepic"]
["type"]=="image/gif"))&&(@$_FILES["profilepic"]["size"] < 1048576)) {
//1 Megabyte
$chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
$rand_dir_name = substr(str_shuffle($chars), 0, 15);
mkdir("userdata/profile_pics/$rand_dir_name");
}
else{
}
}
?>
<p>UPLOAD YOUR PROFILE PHOTO:</p> <br />
<form action="" method="POST" enctype="multipart/formdata">
<img src="./img/default_pic.png" width="70" />
<input type="file" name="profilepic" /><br /><br />
<input type="submit" name="uploadpic" value="Upload Photo"><br />
</form>
its not because of php, the php code is written well the problem is in the html where the html form enctype is written wrong
this
<form action="" method="POST" enctype="multipart/formdata">
should be
<form action="" method="POST" enctype="multipart/form-data">
May be you should try like this (variable name along with a single-inverted comma)
mkdir("userdata/profile_pics/'$rand_dir_name'");
I hope it will work.
Edit some code for your code with this:
Notice that it is best practise to use the variable outside of the string. Also you place the code in an if
statement to check it executed correctly.
edit You also need to start the mkdir
call with a /
or even better start it with $_SERVER['document_root']
so you know you always get an absolute path to the directory you want to generate.
if(mkdir("/userdata/profile_pics/".$rand_dir_name)){
print "this worked!";
}
else {
print "This failed";
}
Also you need to check that the permissions for the parent directory are correct, that the PHP usergroup is allowed to create directories in the /profile_pics/
folder.
You can also check that PHP is in the correct working directory, you can check this with print gwtcwd();