Can upload file using PHP and HTML

Discussion in 'Web Design and Development' started by iphong, Jun 23, 2009.

  1. iphong macrumors member

    iphong

    Joined:
    Aug 28, 2004
    Location:
    Washington, DC
    #1
    So, I try to do a very basic upload 101 with PHP using HTML form. But I can't get it to work.

    HTML file submit the file to a PHP file,

    in the PHP file i try to debug by doing this

    PHP:
    echo 'File name:' $_FILES['uploadedfile']['name'];
    echo 
    'Temp name:' $_FILES['uploadedfile']['tmp_name'];
    the $_FILES['uploadedfile']['name'] returns blank, it means that file wasn't sent to server somehow. I tried to create a tmp folder in the root folder but it doesn't resolve the problem.

    Any ideas to make this work? By the way, my codes work on my other Yahoo! hosted server, but not on this local server.

    here is the script that I made to quick test. The actual code I used in my applications is too complicated to be posted here.

    PHP:
    $target_path "upload/";

    $target_path $target_path basename$_FILES['uploadedfile']['name']); 

    echo 
    'File name:' $_FILES['uploadedfile']['name'] . '<br>'
    echo 
    'Temp name:' $_FILES['uploadedfile']['tmp_name'] . '<br>';

    if(
    move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
        echo 
    "The file ".  basename$_FILES['uploadedfile']['name']). 
        
    " has been uploaded";
    } else{
        echo 
    "There was an error uploading the file, please try again!";
    }
     
  2. NoNameBrand macrumors 6502

    Joined:
    Nov 17, 2005
    Location:
    Halifax, Canada
    #2
    If your stuff works on a different server, I suspect your php.ini file is setup differently. Check to make sure uploading is allowed and that the max file size is bigger than the file you're trying to upload.
     
  3. SrWebDeveloper macrumors 68000

    SrWebDeveloper

    Joined:
    Dec 7, 2007
    Location:
    Alexandria, VA, USA
    #3
    Also make sure the permissions are set correctly in the upload and target paths on the server. This might mean chmod 777 for those directories, but the previous advice given by NoNameBrand is superb so check that first.
     

Share This Page