Uploading images via php

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bigapb
    New Member
    • Aug 2007
    • 9

    Uploading images via php

    Hi.

    I am using the following code to try and enable users to upload an image. For some reason it is not working; I have checked and rechecked the code. I have also looked at the online manuals as well.

    Can anyone help me please?



    [PHP]

    <?php
    if (isset($_POST['submit']))
    {

    $uploaddir ="../recruit/";
    $uploadfile=$up loaddir . $_FILES['agy']['nm'];
    $agy =$_FILES['agy']['nm'];

    if ($agy)
    {
    move_uploaded_f ile($_FILES['agy']['tmp_nm'], $uploadfile);
    }
    elseif (empty($agy))
    {
    $agy='No logo available';
    }
    }
    ?>

    <form enctype = "multipart/form-data" action = "<?php echo $_SERVER['PHP_SELF']; ?>" method = "post">
    <input type = "file" name = "agy" value = ""/>

    <br/>

    <br/>

    <input class = "gobut" type = "submit" name = "submit" value = "upload logo" tabindex = "13"/>
    </form>

    [/PHP]
    Last edited by bigapb; May 2 '08, 12:37 PM. Reason: Could not view whole message
  • ronverdonk
    Recognized Expert Specialist
    • Jul 2006
    • 4259

    #2
    You do not have a name=MAX_FILE_S IZE statement in your form, like this one[code=html] <input type="hidden" name="MAX_FILE_ SIZE" value="9999999" />[/code]Ronald

    Comment

    • ronverdonk
      Recognized Expert Specialist
      • Jul 2006
      • 4259

      #3
      You are double posting in the same forum! See the Posting Giuideline sbefore you continue in this forum.

      Your double thread will be removed.

      moderator

      Comment

      • Atli
        Recognized Expert Expert
        • Nov 2006
        • 5062

        #4
        Two things you could try..
        First, you use the ['nm'] and ['tmp_nm'] elements of the $_FILES array.
        Shouldn't that be ['name'] and ['tmp_name']?

        Second, and I don't really know if this is an issue or not (doesn't hurt to check tho :P).
        You have spaces between your HTML parameters and their values. Could try to remove them, see if it changes anything. Like:
        [code=html]
        <!-- Instead of -->
        <input type = "text" name = "whatever" />

        <!-- Try -->
        <input type="text" name="whatever" />
        [/code]
        This also looks somewhat cleanerm, in my opinion.
        Originally posted by ronverdonk
        You do not have a name=MAX_FILE_S IZE statement in your form, like this one[code=html] <input type="hidden" name="MAX_FILE_ SIZE" value="9999999" />[/code]Ronald
        Even tho the manual says it 'must precede the file input field', this will not cause the upload to fail if missing.
        It appears to be more of an optional way to prevent clients from uploading large files that the server will reject due to their size.

        Comment

        Working...