Php Upload Permission Problems?

Discussion in 'HTML / PHP / JavaScript / CSS' started by FineEdge, Apr 15, 2010.

  1. I've been getting this error message with my upload script in PHP.

    The script appears to work fine on all other servers (including my windows IIS server), but I'm having a little difficulty here.

    The error I receive is:

    PHP Warning: File upload error - unable to create a temporary file in Unknown on line 0 PHP Warning: File upload error - unable to create a temporary file in Unknown on line 0

    Is there any solution to this?

    Thanks and Best Regards.
     
  2. Ramses

    Ramses Guest

    Did you specify a path to use for temp files? do you have a full error or is that it?
     
  3. mjp

    mjp

    Yeah, as Ramses suggests, the default path in the global php.ini will error out because by default the value is null.

    Try this; go to Control Panel Account Information and get your Server Path. It will be something like: e:\web\youraccount\htdocs

    Then in your script use ini_set:
    ini_set("upload_tmp_dir", "e:\web\youraccount\htdocs\yourtempdir");​
    I didn't test that (I don't have a php file upload script at hand), but upload_tmp_dir is what you're looking to change.

    Depending on your script you may be able to also do a simple:
    $uploaddir = "e:\web\youraccount\htdocs\yourtempdir";​
    Depends on where/how the temp dir is defined.
     
  4. Thanks for your responses, I've tried editing the upload_tmp_dir variable, to no success.

    I use

    ini_set("upload_tmp_dir", "e:\web\<my account folder>\htdocs\tempdir");

    and I simply get this error.

    PHP Warning: File upload error - unable to create a temporary file in Unknown on line 0

    Could it be a result of anything else?

    I read this thread, before I came here:
    http://community.discountasp.net/showthread.php?t=9227&highlight=unable+create+temporary+file

    And he was having the same problem I am, but he fixed it saying that
    How do I do the same?

    Thanks for your help so far.
     
  5. mjp

    mjp

    Since the error still says "unknown" it would appear that ini_set() isn't working, so I don't think it's a permissions issue (yet ;)).

    Check your script for someplace the temp dir is defined. You should be able to change it:
    $uploaddir = "e:\web\youraccount\htdocs\yourtempdir";​
    $uploaddir there is just an example...all of this depends on how things are defined in your script. Is this part of a larger application or something you wrote?
     
  6. Thanks for your being patient with me lol, I can be a bit of a nuisance to support at times, but yeah, the script is entirely written by me. There isn't a part of it that I have ceded to another.

    But yes, I think the problem is ini file related, but the actual error occurs at Line 0, this is basically before any script executes, because it uploads the files to a temporary folder and then allows you to move that file with php code. Namely move_uploaded_file()

    I use the code like this:

    move_uploaded_file($_FILES['uploaded']['tmp_name'][$upl], $target)

    The first rather complicated variable is a form of associative array which gives me the name of the temporary file that was uploaded and it's path in the temporary folder where it was uploaded too.

    I basically move that too: $target which is defined before hand as

    $target = IMAGE_DIR;

    which is a constant previously defined as:

    define("IMAGE_DIR", "./pictures/album/images/"); (I've tried this with and withour the './' )

    This all works on my machine, but of course there's a variety of different settings here. But still the error seems to occur before any code is executed, because PHP uploads files into temporary folders before the code on the page executes.

    Could this be permissions?
     

Share This Page