TheLiveitup34
TheLiveitup34

Reputation: 101

php move_uploaded_file wont move the file to the hosted server

I don't know how to fix this but the problem is that it won't upload to the server that I'm using to host the website it creates the folder just fine but won't move it. The coding for the moving is below.

This is the error I get Warning: move_uploaded_file(./userdata/profile_pics/iOy1pQXTZsLw7VA/) [function.move-uploaded-file]: failed to open stream: Is a directory in /home/a4640336/public_html/account_settings.php on line 103

and as well as this error code

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phpX1zVno' to './userdata/profile_pics/iOy1pQXTZsLw7VA/' in /home/a4640336/public_html/account_settings.php on line 103

 move_uploaded_file(@$_FILES["profilepic"]["tmp_name"],"./userdata/profile_pics/$rand_dir_name/".$FILES["profilepic"]["name"]);
        echo "Your profile pic has been updated!".@$_FILES ["profilepic"]["name"];
        //$profile_pic_name = @$_FILES["profilepic"] ["name"];
        //$profile_pic_query= mysql_query("UPDATE users SET profile_pic='$rand_dir_name/$profile_pic_name' WHERE username='$username'");
        //header("location: account_settings.php");

Overall I have tried to change where it is located to have it leading directly from the source but it doesn't change. If anyone can help please help me!

PS the commented out parts were done to be able to see the error

Upvotes: 1

Views: 2799

Answers (2)

Dhaval Patel
Dhaval Patel

Reputation: 1106

you need to use server path for file upload

$files = glob($_SERVER["DOCUMENT_ROOT"]."/myFolder/*");

$_SERVER["DOCUMENT_ROOT"] will get server path like var/host/public_html/your_folder

May this help you

Upvotes: 0

Codingalien
Codingalien

Reputation: 3047

For those using PHP on Windows and IIS, you SHOULD set the "upload_tmp_dir" value in php.ini to some directory around where your websites directory is, create that directory, and then set the same permissions on it that you have set for your websites directory. Otherwise, when you upload a file and it goes into C:\WINDOWS\Temp, then you move it to your website directory, its permissions will NOT be set correctly.And If you try to upload a file larger than the post_max_size value (or multi files), the page will only refresh itself and no errors are thrown.

The destination directory must exist; move_uploaded_file() will not automatically create it for you.

You must

  1. make sure that the file is not empty.

  2. make sure the file name in English characters, numbers and (_-.) symbols, For more protection.

  3. make sure that the file name not bigger than 250 characters.
  4. Check File extensions and Mime Types that you want to allow in your project. You can use : pathinfo(). or you can use regular expression for check File extensions as in example
  5. Check file size and make sure the limit of php.ini to upload files is what you want, You can start from here.
  6. Check the file content if have a bad codes or something like this function
 move_uploaded_file($_FILES["file"]["tmp_name"], "../uploads/" . $_FILES["file"]["name"]);

Also check dir have writable permission

Upvotes: 1

Related Questions