Results 1 to 3 of 3

Thread: How can I upload a file by php coding

  1. #1
    Geek_Guest
    Guest

    How can I upload a file by php coding

    Question asked by visitor Arnab

    How can I upload a file by php coding?

    I have been try it by xamapp .But the code is running local machine . but when I upload the code on the other server some where the code is not running.

    my code as :
    ***************

    if($_REQUEST['Submit']=='Submit')
    {


    if (($_FILES['fupload']['type'] == "image/gif")|| ($_FILES['fupload']['type'] == "image/jpeg")||($_FILES['fupload']['type'] == "image/pjpeg")){


    $archive_dir="thum_imges";
    echo $userfile=$_POST['fupload'];
    echo "
    ";
    echo $userfiled=$_FILES['fupload']['tmp_name'];
    echo "
    ";
    echo $filename=$_FILES['fupload']['name'];
    echo "
    ";
    $filenm=basename($filename);

    // $up= copy($userfiled,"$archive_dir/$filenm") ;
    $up= move_uploaded_file($userfiled,"$archive_dir/$filenm") ;

    echo "

    up = $up

    ";
    }//End of file check if
    }
    ?>


  2. #2
    Junior Member
    Join Date
    Nov 2007
    Answers
    3

    Re: How can I upload a file by php coding

    first of all, try to avoid using REQUEST variable,
    it is too "heavy", i mean in REQUEST You have POST and GET
    so try to send form, especially files, only using POST

    //////
    second thing, try to debug using
    var_dump


    and try to find out, if those variables really exists
    if the $_REQUEST['Submit']=='Submit'

    if(isset($_REQUEST['Submit']) && $_REQUEST['Submit'] == 'Submit')
    {

    //here do You code
    }
    else
    {
    //echo "The form was incorrectly sent";
    }

    ////
    3rd problem which can occour, that You haven't granted
    enough privileges for write access

    ///
    4rd problem, on many servers the global variables
    are turned off,

    Hope You find those usefull

    Charles


  3. #3
    Junior Member
    Join Date
    Aug 2008
    Answers
    3

    Re: How can I upload a file by php coding

    we can upload a file using php.

    if(is_uploaded_file($_FILES['yourfilename']['tmp_name'], pathname)
    {
    echo "file is already uploaded ";
    move_uploaded_file($_FILES['yourfilename']['tmp_name'], pathname)
    {
    echo "replace the previous file from new file(having the same name) ";
    }

    }
    else
    {
    echo "file is not uploaded so i need to upload a file first time";

    }


    and if u are upload a file first time . u have to write enctype='multiple/form-data'
    inside a form tag.


    BY
    ANUJ MAHESHWARI

    Last edited by anujm1_1; 08-21-2008 at 05:17 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
About us
Applying for a job can be a stressful and frustrating experience, especially for someone who has never done it before. Considering that you are competing for the position with a at least a dozen other applicants, it is imperative that you thoroughly prepare for the job interview, in order to stand a good chance of getting hired. That's where GeekInterview can help.
Interact