Not working =[

Discussion in 'PHP' started by Sygon, May 8, 2007.

  1. #1
    This upload script i made is not working.

    Link: http://59codes.com/uploader/test.php

    Try upload something to get the error.

    Source:

    
    
    <?
    if($_POST['submit'])
    {
    $uploadpath = "uploads"; // Upload path
    $filesizemax = "2097512"; // Max file size
    $filetypesallowed = array(".gif",".jpg",".png"); // File types allowed
    
    ### Set variables
    
    $tempfile = $_FILES['file']['tmp_name'];
    $filename = $_FILES['file']['name'];
    $filesize = $_FILES['file']['size'];
    
    ### Begin upload
    
    if($filename == NULL or $filesize = "0")
    
    {
    
    echo "File invalid";
    die;
    }
    else
    {
    
    $typenow = strtolower(strstr($filename,".")); // Converters text to lower cases and then serperates the filename from the gif/jpg/png
    
    if(!in_array($typenow,$filetypesallowed))
    
    {
    echo "file type not allowed";
    die;
    }
    else
    {
    
    if($filesize > $filesizemax)
    
    {
    echo "File is too big";
    die;
    }
    else
    {
    
     if (move_uploaded_file($tempfile,"$uploadpath")) {
     
     echo "file uploaded - <a href='$uploadpath/$filename$typenow'>Click</a>";
     
     }
     
     else
     
     {
     echo "error could not move file";
     }
    
    }
    }
    
    }
    
    
    }
    ?>
    
    <form method="post" enctype="multipart/form-data" name="form1" action="<?php $_SERVER['PHP_SELF']; ?>">
      <label>
      <input type="file" name="file" id="fileField">
      </label>
      <label>
      <input type="submit" name="submit" id="button" value="Submit">
      </label>
    </form>
    
    
    
    PHP:
    Thanks
     
    Sygon, May 8, 2007 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    
    if($filename == NULL or $filesize = "0")
    
    PHP:
    ;)
     
    nico_swd, May 8, 2007 IP
  3. Sygon

    Sygon Peon

    Messages:
    439
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Yet that is not the error..?
     
    Sygon, May 8, 2007 IP
  4. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #4
    Well it's one. I didn't try uploading until now.

    
    if (move_uploaded_file($tempfile, $uploadpath . $filename)) {
    
    PHP:
    The second argument should be the full path and file name.
     
    nico_swd, May 8, 2007 IP
  5. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #5
    
    
    //this should be
    
    if($filename == NULL or $filesize == "0")
    
    
    PHP:
     
    jestep, May 8, 2007 IP
  6. Sygon

    Sygon Peon

    Messages:
    439
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Got it working :)
     
    Sygon, May 8, 2007 IP