Results 1 to 12 of 12
  1. #1

    PHP uploading trouble

    Hi guys, sorry if this has been asked before but I did searches through the forms and couldn't find anything that solved my problem. I've just moved to a new server and I'm having some trouble uploading files in PHP. It doesn't work in my php board, but also in a simple PHP form I wrote a long time ago:

    Here's the code for the handler:

    PHP Code:


    $file_name != "")
    copy("$file","/path/to/$file_name") or die("Could not copy file!");
    "No file specified!");


    <head><title>Upload Complete</title></head>

    <font size=2 face=tahoma>
    <h3>File upload succeeded...</h3>
    <li>Sent: <?php echo("$file_name"); ?>
    <li>Size: <?php echo("$file_size"); ?> bytes
    <li>Type: <?php echo("$file_type"); ?>

    <img src="<?php echo("$path$file_name"); ?>"><br>
    <?php echo("$path$file_name"); ?>

    and the html:

    PHP Code:

    font size=2 face=tahoma>
    h3>Image Uploader</h3>
    Select a file to upload:

    form action="uploader.php" method="post" enctype="multipart/form-data">
    input type="file" name="file" size="50">
    input type="submit" value="Upload File">


    I always get "No file selected". I'm running Apache 2 (was 1.3 on my old server) on rh9 with only the modules core.c, prefork.c, http_core.c, mod_so.c.

    Would this be a problem with suexec, phpsuexec? I've disabled Safe_mode in php.ini and restarted httpd but that didn't help.

    Would appreciate any pointers.


  2. #2
    Join Date
    Jan 2003
    Perth, WA, Australia
    I can't see where you're specifying $file_name ... ? :: coming soon

  3. #3
    doesn't PHP automatically create the variables $file_name, $file_size, $file_type for the text input "file"?

    It works perfectly on the old server but not on the new one. Nothing is set for the tmp_directory in php.ini


  4. #4
    ...just change it to
    if($file != "")

    see what happens

  5. #5
    On your new server you've probably got register_globals = Off (which is a good thing). Your old server probably had it on, and that explains why this script used to work for you, and doesn't anymore.

    Set regsiter_globals Off in your php.ini file and restart apache, you should be good to go there.

  6. #6
    Join Date
    Apr 2003
    London, UK
    You want to use the autoglobal $_FILES, that'll return all the info you need, e.g $_FILES['input_name']['name'] $_FILES['input_name']['size'] etc

    check here for more info, and you should think about restricting file extensions and sizes to stop people uploading nasty stuff

  7. #7
    thanks for the replies. I set register_globals on (you're right, they were on on the last server), set the upload_tmp_dir to /tmp (made it writable), commented out the disable_functions line, disabled safe_mode but haven't had any luck.

    File uploading isn't working on a PHP gallery and board that I use too so I know it's a server issue and not something with my script.

    Any other suggestions guys?

  8. #8
    Join Date
    Nov 2003
    Ljubljana, Slovenija, Europe
    If you are putting your images in a folder, it's mostly likely you do not have the credentials to do so. This means you have to alter the relevant directory mode, that's change mode to some higher privileges. As you have it now, it's probably set only to read, so you can not write to it. Change the mode to something like 777 and it should be alright.

    Hope it helped. Airnine

  9. #9
    thanks airnine, but the folders all have 777 permissions set.

  10. #10
    Join Date
    Nov 2003
    Ljubljana, Slovenija, Europe
    Hi again, I didn't look at your code before, but now I did and must tell you that your source from where to copy and destination where to copy look a bit funky, I bet your problem is there

    for one thing, you should first check if the file you submitted in the form arrived to the server!!!

    and what's this "$file" ?? where is it defined??

    how to you know this is the right path and it exists "/path/to/$file_name" ? shouldn't you check for it?

    to get the destination you should define where your destination folder is relatively located regarding this script and then get the real path
    for example


    Perhaps you should try the above. Good luck!


  11. #11
    Join Date
    Apr 2004
    Lahore, Pakistan

    Talking print_r($_FILE['html_filefield']) ;

    print $_FILE array using print_r($_FILE['html_FileFieldName']); and check wht's coming in all fields... is file uploaded in tmp folder on server... may it help A key to Freelance Development
    Windows Live IM: [email protected]
    E: [email protected]

  12. #12
    thanks again guys. I spent yesterday reading through the php documentation and articles by people who've had similar problems, but unfortuantely nothing has worked.

    I've been able to narrow down the problem to the /tmp folder since files don't even temporarily get uploaded to it even though it has drwxrwxrwt permissions. it's ownership/group permissions are all set to root. I've tweaked everything possible in php.ini from allowing file uploads to disabling/enabling safe mode and register_globals, all to no avail.

    hmmm...I don't really know what else to try.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts