+ Reply to Thread
Results 1 to 7 of 7

Thread: Php upload error

  1. #1
    thefattredd's Avatar
    thefattredd is offline x10Hosting Member thefattredd is an unknown quantity at this point
    Join Date
    Apr 2010
    Location
    127.0.0.1
    Posts
    5

    Question Php upload error

    I am trying to create a script that allows admins to update a feed that consists of an image and a bunch of text. The processing the text only works just fine, but I get the following error with the image:

    Warning: copy() [function.copy]: open_basedir restriction in effect. File() is not within the allowed path(s): (/home/:/tmp) in /home/fattredd/public_html/test/newlocation.php on line 11
    Error uploading

    What does this mean? Heres my processing script:

    PHP Code:
    <?php
        
    require_once 'conn.php';
        include 
    'parts/header.php';
        
    $name $_POST['name'];
        
    $link $_POST['link'];
        
    $description $_POST['description'];
        
    $image_alt $_POST['image_alt'];
        
        
    $path"uploads/".$HTTP_POST_FILES['image']['name'];
        if(
    $image !=none) {
            if(
    copy($HTTP_POST_FILES['image']['tmp_name'], $path)) {
                echo 
    "File Name :".$HTTP_POST_FILES['image']['name']."<BR/>"
                echo 
    "File Size :".$HTTP_POST_FILES['image']['size']."<BR/>"
                echo 
    "File Type :".$HTTP_POST_FILES['image']['type']."<BR/>"
                echo 
    "<img src=\"$path\" width=\"150\" height=\"150\"><br><br><br><br><br>";
            } else {
                echo 
    "Error uploading";
            }
        }
        
        
    $sql "INSERT INTO `locations` (link, description, image_url, image_alt)" .
                
    " VALUES (" $link ", " $description ", " $path ", " .
                
    $image_alt ")";
        
    $result=mysql_query($sql);
        
            echo 
    "<div class=\"content_entry\">" .
                
    "<div class=\"thumbnail\"><img src=\"" $HTTP_POST_FILES['image']['name'] . "\" width=\"118\" height=\"88\" alt=\"" $image_alt "\" /></div>" .
                
    "<div class=\"entry_text\">" .
                
    "<h3>" .
                
    "<a href=\"" $link "\">" $name "</a>" .
                
    "<br />" .
                
    "</h3>" .
                
    "<p>" $description "</p>" .
                
    "</div>" .
                
    "<div class=\"clearthis\">&nbsp;</div>" .
                
    "</div>";
    ?>
    I use conn.php to connect to my database and parts/header.php to format the page

  2. #2
    misson is offline x10 Spammer misson is a jewel in the rough
    Join Date
    Mar 2008
    Location
    Libertatia
    Posts
    2,506

    Re: Php upload error

    Read up on the open_basedir directive. Anything outside the /home and /tmp hierarchies can't be accessed from PHP. Print the path on any line that generates a notice to get a better idea of what's happening. You can always search the forums for more information.
    Last edited by misson; 06-01-2010 at 07:22 PM.
    Be sure to read all pages linked in this post; they have further information that should prove useful. When asking for help, make sure you follow Eric Raymond's and Jon Skeet's guidelines for prompt, accurate responses. Please answer any questions I ask; they're not rhetorical (probably). Any posted code is intended as illustrative example, rather than a solution to your problem to be copied without alteration. Study it to learn how to write your own solution.
    Misson, not Mission.

  3. #3
    thefattredd's Avatar
    thefattredd is offline x10Hosting Member thefattredd is an unknown quantity at this point
    Join Date
    Apr 2010
    Location
    127.0.0.1
    Posts
    5

    Re: Php upload error

    How can I fix my script?

  4. #4
    kadai's Avatar
    kadai is offline x10Hosting Member kadai is an unknown quantity at this point
    Join Date
    Apr 2010
    Posts
    51

    Re: Php upload error

    Very interesting that it does not work.

    First of all, I wonder why you use "$HTTP_POST_FILES" instead of "$_FILES", I recommend the second because that is the way it should be used by now (PHP5 and latter) and my scripts works correctly with that variable.

    A way to debug it is to (having a script that simply uploads the image) see what does PHP have for the FILES array:

    Code:
    print_r($_FILES);
    And of course, if you get an empty array, it may be an indication that you are not using the correct 'name' in the array's key.

    For example, the "upload" might be different if you are using a "name" indicator in your input field.

    Having <input name=myupload type=file> will generate an usable array like this:
    $_FILES['myupload']

    Just notations, to make sure that you are trying to copy the correct file.

  5. #5
    thefattredd's Avatar
    thefattredd is offline x10Hosting Member thefattredd is an unknown quantity at this point
    Join Date
    Apr 2010
    Location
    127.0.0.1
    Posts
    5

    Re: Php upload error

    I'm only using $HTTP_POST_FILES because that was suggested to me by a friend. I'm kinda new with uploading files and such. Thanks a lot for your input and help to solving this problem. I'll try it out as soon as i can

  6. #6
    kadai's Avatar
    kadai is offline x10Hosting Member kadai is an unknown quantity at this point
    Join Date
    Apr 2010
    Posts
    51

    Re: Php upload error

    You welcome :3
    One way to debug efficiently your scripts is to print variables in an arbitrary way to see if they are having an expected value when entering a processing stage (In your case, moving and handling the uploaded file)

    Now, giving it even a second close look, I detected this:
    Code:
    if($image !=none) {
    But then I have not seen where $image was set a value, so, it is by nature NULL (undeclared) what can be also causing the problem.

  7. #7
    varunaroli is offline x10Hosting Member varunaroli is an unknown quantity at this point
    Join Date
    Jan 2009
    Posts
    4

    Re: Php upload error

    You just try this code....



    <?php

    if ((($_FILES["image"]["type"] == "image/gif")
    || ($_FILES["image"]["type"] == "image/jpeg")
    || ($_FILES["image"]["type"] == "image/bmp")
    || ($_FILES["image"]["type"] == "image/pjpeg")))
    {
    if ($_FILES["image"]["error"] > 0)
    {
    echo "Return Code: " . $_FILES["image"]["error"] . "<br />";
    }
    else
    {

    if (file_exists("upload/" . $_FILES["image"]["name"]))
    {

    }
    else
    {
    move_uploaded_file($_FILES["image"]["tmp_name"],"upload/" . $_FILES["image"]["name"]);

    }
    $path=$_FILES["image"]["name"];

    ?>

+ Reply to Thread

Similar Threads

  1. ftp upload error
    By developerno1 in forum Free Hosting
    Replies: 3
    Last Post: 05-25-2009, 01:01 PM
  2. Replies: 2
    Last Post: 11-01-2008, 09:48 PM
  3. Upload error
    By cyberbenb in forum Scripts & 3rd Party Apps
    Replies: 0
    Last Post: 09-13-2007, 12:54 AM
  4. Upload error
    By wefrnds in forum Scripts & 3rd Party Apps
    Replies: 0
    Last Post: 09-12-2007, 04:10 PM
  5. Gallery upload error
    By digitaljit in forum Free Hosting
    Replies: 2
    Last Post: 06-26-2007, 11:19 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers