SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast ante's Avatar
    Join Date
    Aug 2004
    Location
    Split, Croatia
    Posts
    33
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Problem with upload script

    I have some upload code and there is some error. It's driving me crazy, so please, I would need some help

    From form I have
    HTML Code:
    <input name="uploadfile" type="file" class="button" size="20">
    So, that is $uploadfile variable.

    here is php:

    PHP Code:
    $conn_id ftp_connect("site.org");
    ftp_login($conn_id"user""pass");
    $path "/home/site/public_html/$user";
    $filetyp substr($uploadfile, -3);
    if ((
    $filetyp == 'gif') OR ($filetyp == 'jpg')) {
    copy($uploadfile$path) or die();
    $handle fopen($path "/" $uploadfile,'r');
    $file_content fread($handle,filesize($path "/" $uploadfile));
    fclose($handle);
    ftp_close($conn_id);
    $encoded chunk_split(base64_encode($file_content));
    $sql "Here goes sql code...";
    } else { echo 
    "Wrong type of file. ONLY .JPG and .GIF allowed."; } 
    From this I have an error that filetype is wrong

    Any help welcome.

    Many thanks,
    Ante

  2. #2
    SitePoint Evangelist
    Join Date
    Mar 2005
    Posts
    423
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Make sure your form has the right encoding type for an upload. This example is taken from the manual:
    PHP Code:
    <!-- The data encoding typeenctypeMUST be specified as below -->
    <
    form enctype="multipart/form-data" action="__URL__" method="POST">
        <!-- 
    MAX_FILE_SIZE must precede the file input field -->
        <
    input type="hidden" name="MAX_FILE_SIZE" value="30000" />
        <!-- 
    Name of input element determines name in $_FILES array -->
        
    Send this file: <input name="userfile" type="file" />
        <
    input type="submit" value="Send File" />
    </
    form
    and this:
    PHP Code:
     $conn_id ftp_connect("site.org"); 
    does this need the full path? ie http://www?

    You might also want to look for the position of the . then get the extension from there, instead of taking the last 3 characters from the end. For instance, someones image file might have the .jpeg extension.
    PHP Code:
    $filetyp substr($uploadfile, -3); 
    This would return jpe in this case.
    I'd use:
    PHP Code:
    $extension substr(strtolower(strrchr($filename".")), 1); 
    When you submit a file form, it populates the $_FILES superglobal array. From here you can access all the details you need. It seems you are making a copy of this array ($uploadfile) and passing it to the copy function. Really, you should use the move_upload_file, and pass it the appropriate $_FILE value.

    Have a read on the manual

  3. #3
    SitePoint Enthusiast ante's Avatar
    Join Date
    Aug 2004
    Location
    Split, Croatia
    Posts
    33
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I did it, thank you.


Bookmarks

Posting Permissions

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