i am currently having a problem and i have tried searching a lot on this topic but i still can't find an answer on why move_uploaded_file is not working, i am able to create directory using mkdir() but move file doesn't seem to work, i have also tried creating custom php.ini file with file_uploads=on in it but still nothing happens and even my directory created in also having 0755 or 755 write and read permissions.
I have tried adding delimiter as in below and just about everything but still nothing happens, I really need to move my uploaded and help would appreciated.
Here is my code :
<?php
//Profile Image upload script
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);
$dir = "./userdata/profile_pics/$rand_dir_name";
mkdir($dir);
if(is_dir($dir . "/" .$_FILES["profilepic"]["name"])) {
echo "sdsadsad";
}
move_uploaded_file($_FILES["profilepic"]["tmp_name"], $dir . "/" .$_FILES["profilepic"]["name"]);
$profile_pic_name = $_FILES["profilepic"]["tmp_name"];
echo $profile_pic_name;
$profile_pic_query = mysqli_query($conn,"UPDATE users2 SET profile_pic='$rand_dir_name/$profile_pic_name' WHERE username='$user'");
}
else
{
$msg5 = "Invailid File! Your image must be no larger than 1MB and it must be either a .jpg, .jpeg, .png or .gif";
}
}
?>
and here is form :
<form action="" method="POST" enctype="multipart/form-data">
<input type="file" name="profilepic" /><br><br>
<input type="submit" name="uploadpic" value="Change Profile Photo">
</form>
Try this
$old_umask = umask(0);
mkdir($dir, 0777);
umask($old_umask);
Try maybe one of these these
<?php
// Read and write for owner, nothing for everybody else
chmod("/somedir/somefile", 0600);
// Read and write for owner, read for everybody else
chmod("/somedir/somefile", 0644);
?>
before moving it anywhere
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.