Saturday, August 18, 2018

php - Warning: move_uploaded_file(): The second argument to copy() function cannot be a directory

There is no solution, as i have searched a lot on moving my uploaded image into directory here is my php code :


  //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);
move_uploaded_file($_FILES["profilepic"]["tmp_name"],"userdata/profile_pics/$rand_dir_name".$_FILES["profile‌​pic"]["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";
}
}
?>

but when I try to upload image,it creates the random folder in userdata/profile_pics but it doesn't move the file into random folder directory i have also created a custom php.ini file with file_uploads = On, but i recieve the following warning when i submit the form :-


Warning: move_uploaded_file(): The second argument to copy() function cannot be a directory in /home/rahulkapoor90/public_html/note.php on line 26


Warning: move_uploaded_file(): Unable to move '/tmp/phpO592dd' to 'userdata/profile_pics/zAGC9wOhVyoe3R5' in /home/rahulkapoor90/public_html/note.php on line 26
/tmp/phpO592dd

No comments:

Post a Comment

plot explanation - Why did Peaches&#39; mom hang on the tree? - Movies &amp; TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...