Results 1 to 4 of 4

Thread: File Upload - Setting a Name

  1. #1
    Join Date
    Mar 2007
    Location
    Currently: New York/Philadelphia
    Posts
    2,735
    Thanks
    3
    Thanked 519 Times in 507 Posts

    Default File Upload - Setting a Name

    Hey guys...

    How do I set a filename using the code below? I'd like for the image to be called header.jpg and overwrite the existing file of the same name.

    PHP Code:
    if (!isset($HTTP_POST_FILES['banner'])) exit; 
        if (
    is_uploaded_file($HTTP_POST_FILES['banner']['tmp_name'])) { 
            if (
    $HTTP_POST_FILES['banner']['size']>$max_size) { echo "The file is too big"; exit; } 
            if ((
    $HTTP_POST_FILES['banner']['type']=="image/jpeg")) { 
                
    $res copy($HTTP_POST_FILES['banner']['tmp_name'], $path 
                
    $HTTP_POST_FILES['banner']['name']); 
                
                if (!
    $res) { $msg2 "Upload Error"; exit; } 
                else { 
    $msg "Update Processed"; } 
                
            } 
            else { echo 
    "Wrong file type"; exit; } 
        } 
        
    $my_file $HTTP_POST_FILES['banner']['name']; 

  2. #2
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Looks like it's $HTTP_POST_FILES['banner']['name']);

    Really, you can just copy the code using move_uploaded_file() from php.net here:
    http://www.php.net/manual/en/features.file-upload.php
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  3. #3
    Join Date
    Mar 2006
    Location
    Cleveland, Ohio
    Posts
    574
    Thanks
    6
    Thanked 5 Times in 5 Posts

    Default

    I'd also use image/jpg in there just to be safe:

    PHP Code:
    if (($HTTP_POST_FILES['banner']['type']=="image/jpeg") || ($HTTP_POST_FILES['banner']['type']=="image/jpg")) { 
    The other thing is that you can use $_FILES instead of $HTTP_POST_FILES...which, I think is a lot easier. But your server and/or PHP version may not support that.

    Anyway, just throwing those things out there.
    Thou com'st in such a questionable shape
    Hamlet, Act 1, Scene 4

  4. #4
    Join Date
    Mar 2007
    Location
    Currently: New York/Philadelphia
    Posts
    2,735
    Thanks
    3
    Thanked 519 Times in 507 Posts

    Default

    Thanks guys...

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
  •