Image not moved

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • vjayis
    New Member
    • Mar 2008
    • 134

    Image not moved

    hi

    i hav been using

    Code:
    move_uploaded_file($_FILES["image"]["tmp_name"],"foldername/".$filename);
    to store images.,

    when i m using it in my local server it works well., but when uploaded the IMAGE is NOT MOVED to the desired folder.,

    And i m sure that there exists a folder where the image is being stored., and even tried by using COPY() instead of MOVE_UPLOADED_F ILE()., but it too doesnt work.,

    and i didnt even get any errors.,

    do i need to check any server configuration.. ..

    i m stuck with this error and cant move over it...

    thanks
    vijay
  • Markus
    Recognized Expert Expert
    • Jun 2007
    • 6092

    #2
    Vjayis,

    Please post your questions in the 'answers' forum, not the 'insights' forum. The Insights forum is for articles, not questions.

    Thanks,
    Moderator.

    Comment

    • Markus
      Recognized Expert Expert
      • Jun 2007
      • 6092

      #3
      You maybe have different settings in your php.ini file, such as upload_max_file size.

      do you have access to your server configuration on the online server?

      Thanks,
      Markus.

      Comment

      • vjayis
        New Member
        • Mar 2008
        • 134

        #4
        hey yar., sorry i realized that i hav posted in the wrong place after my submission., i was little bit confused due to the change of layout., hope it wont happen again.,

        and as u said i have checked the maximum file size for upload_max_file size through phpinfo() command and it i found it to be 32M there...

        Comment

        • Markus
          Recognized Expert Expert
          • Jun 2007
          • 6092

          #5
          What is the post_max_size set to?

          Comment

          • Atli
            Recognized Expert Expert
            • Nov 2006
            • 5062

            #6
            Hi.

            A couple of suggestions.

            Try echoing $_FILES['image']['error'].
            If the upload was successful, this should print 0. If it is not 0, you can see what the error code means here.

            Make sure you have permission to write the the destination folder.
            An easy way to determine what permissions you have is to create a new file and do something like:
            [code=php]
            <?php
            $destinationDir = "/path/to/upload/dir/";

            echo "<h3>Dir: $destinationDir </h3>";
            if(is_readable( $destinationDir )) {
            if(is_writable( $destinationDir )) {
            echo "You have full control over this directory.";
            }
            else {
            echo "You can read, but not write. Putting uploaded files here won't work!";
            }
            }
            else {
            echo "You have no access to this directory. Not even to read it.";
            }
            ?>
            [/code]

            Comment

            • vjayis
              New Member
              • Mar 2008
              • 134

              #7
              hi

              post_max_size set to 30M..,,

              and i tried echoing $_FILES['image']['error'] which results in 0; but the image is not uploaded..

              and atlast when i tried pasting the code given by you in a file and uploaded it into my root directory to see whether i hav permission to access the folder, i got the result as follows:

              when i gave full path as
              Code:
              <?
              $destinationDir = "http://mysite.com/Admin/gimages/";
              .....................code........................
              ?>
              result:
              "You have no access to this directory. Not even to read it."

              And when i gave the path as.,
              Code:
              <?
              $destinationDir = "Admin/gimages/";
              .....................code........................
              ?>
              result:
              "You can read, but not write. Putting uploaded files here won't work!"

              So how can i proceed.,

              thanks

              Comment

              • Markus
                Recognized Expert Expert
                • Jun 2007
                • 6092

                #8
                move_uploaded_f ile() only accepts a relative path. So, http://... won't work. The folder you are trying to upload to doesn't have the correct permissions. Have a look at PHP: chmod - Manual to learn how to set folder permissions.

                Comment

                • vjayis
                  New Member
                  • Mar 2008
                  • 134

                  #9
                  hi., i go through the page and i m not able to set folder permission.,

                  i pasted this code in a file in the root directory
                  Code:
                  <?php 
                        $permissions = 'drwxr-xr-x';  // or whatever 
                        $mode = 0; 
                  
                        if ($permissions[1] == 'r') $mode += 0400; 
                        if ($permissions[2] == 'w') $mode += 0200; 
                        if ($permissions[3] == 'x') $mode += 0100; 
                        else if ($permissions[3] == 's') $mode += 04100; 
                        else if ($permissions[3] == 'S') $mode += 04000; 
                  
                        if ($permissions[4] == 'r') $mode += 040; 
                        if ($permissions[5] == 'w') $mode += 020; 
                        if ($permissions[6] == 'x') $mode += 010; 
                        else if ($permissions[6] == 's') $mode += 02010; 
                        else if ($permissions[6] == 'S') $mode += 02000; 
                  
                        if ($permissions[7] == 'r') $mode += 04; 
                        if ($permissions[8] == 'w') $mode += 02; 
                        if ($permissions[9] == 'x') $mode += 01; 
                        else if ($permissions[9] == 't') $mode += 01001; 
                        else if ($permissions[9] == 'T') $mode += 01000; 
                  
                        printf('Mode is %d decimal and %o octal', $mode, $mode); 
                  ?>
                  and the got the result as
                  "Mode is 493 decimal and 755 octal"

                  And they hav specified tht it should be changed to 0750 frm 755

                  so i tried by placing the following code in the same file

                  Code:
                  chmod("Admin/gimages/imagename.jpg", 0750);
                  but no change occoured...

                  i dont knw how to proceed.,

                  can u tell me wht i had to do......

                  Comment

                  • vjayis
                    New Member
                    • Mar 2008
                    • 134

                    #10
                    Is there anyone to guide me..,,

                    Comment

                    • Atli
                      Recognized Expert Expert
                      • Nov 2006
                      • 5062

                      #11
                      The chmod function probably won't help you here.
                      You will most likely require at least write permission on a folder to be able to chmod it with PHP.

                      How do you access the remote server? Through an FTP connection? Something else?

                      Which ever method you used to create the directory, that would also be the way you would change the permission for that directory.
                      Like, if you use FTP to connect to the server and upload your files, you would have to use the FTP chmod command to change the permission for them.

                      The FTP user you connected with would be the owner of those files, and as such, he would (usually) have to be the one to set the permission for them.

                      Comment

                      • vjayis
                        New Member
                        • Mar 2008
                        • 134

                        #12
                        thanks yar., i hav changed the file attributes settings through my FTP and it works fine.,

                        Comment

                        • Banfa
                          Recognized Expert Expert
                          • Feb 2006
                          • 9067

                          #13
                          As a security precaution if you are going to change the directory permissions to allow file writes then it is a wise idea to create a sub-directory and set the relaxed permissions on that directory rather than relax the permissions of your root directory.

                          Comment

                          • vjayis
                            New Member
                            • Mar 2008
                            • 134

                            #14
                            ya i hav done as u hav suggested above., i hav changed the permissions only to my sub directories..

                            Comment

                            • FLEB
                              New Member
                              • Aug 2008
                              • 30

                              #15
                              Also-- you might already know this, but it's worth noting anyhow-- be careful who you let upload, and what you let them upload.

                              I've actually been bitten by this once, although, in my defense, it was only from a site I maintained, not a script I created, configured, or selected (There... ass adequately covered). There was a mailer script, an old Perl job from the stone age, at least. The problem was that it put any and every uploaded file into a Web-visible "uploads" folder, and just included a link to the file in the email. Handy, but dangerous.

                              I ended up getting a frantic call that someone was running a phishing site, completely out of the uploads folder. They just "mailed" their HTML files and images, one by one. There was no extension or mime-type filter on the uploader, and the folder had full Web access, so anything that got "mailed", be it a PHP script, an image, or an HTML page, was Web-visible and processed.

                              Make sure you filter out nasty filetypes, and if you don't need the results to be web-visible from their placed location, you can use an .htaccess file to make them Web-inaccessible.

                              Comment

                              Working...