April 1, 2012

php file upload permission?

Question by user1200640

I am using the following script to upload pictures to my website. It is working perfectly on my local machine. but when I am running on my FTP account with godady it showing me the permission error. I already gave it the 777 permission from my client FTP, but it is still showing me this.

<?php
include ("login.php");
if ($_POST['submit']){


    $name = $_FILES['upload']['name'];
    $temp = $_FILES['upload']['tmp_name'];
    $type = $_FILES['upload']['type'];
    $size = $_FILES['upload']['size'];

    if (($type == "image/jpg") || ($type == "image/png") || ($type == "image/gif") || ($type == "image/jpeg")){
        if  ($size <= 1000000){

                move_uploaded_file($temp,$name);
                echo "<img src='$name'>";
            } else {
                    print"your image file is too big";
                }

        }else {
                print "this file type is not allowed!";
            }


    }else{
            header ("Location: login.php");
        }


?> 

and

<form action="upload.php" method="post" enctype="multipart/form-data">
File: <input type="file" name="upload">
<input type="submit" name="submit" value="Upload!">
</form>

the problem:

Warning: move_uploaded_file(1 (12).jpg) [function.move-uploaded-file]: failed to open stream: Permission denied in D:Hosting8923686htmluploadedimagesupload.php on line 13

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move 'D:TempphpphpF893.tmp' to '1 (12).jpg' in D:Hosting8923686htmluploadedimagesupload.php on line 13

How do I fix this problem ?

Answer by Starx

Your webserver does not have access to your local drives.

D:Hosting8923686htmluploadedimages is invalid

Use relative path which points to your folder, not the direct path

Something like

move_uploaded_file($temp, "uploadedimages/$name");

Author: Nabin Nepal (Starx)

Hello, I am Nabin Nepal and you can call me Starx. This is my blog where write about my life and my involvements. I am a Software Developer, A Cyclist and a Realist. I hope you will find my blog interesting. Follow me on Google+

...

Please fill the form - I will response as fast as I can!