www.webdeveloper.com
Results 1 to 4 of 4

Thread: Problem Naming Uploaded Images

  1. #1
    Join Date
    Apr 2013
    Posts
    8

    Problem Naming Uploaded Images

    Script #1 resizes uploaded images and saves them to my "newphotos" folder as "resized.jpeg" or any other name I choose.

    Script #2 does the same thing but names the uploaded image with the user's name from the input form.

    I need to know which photo goes with which user, but can't get script #2 integrated properly into script #1. I've tried replacing $image->save in Script #1 with the move function from Script #2 with all sorts of variations with no success.

    I'm just learning PHP code so any help coming my way would be very appreciated. Thanks,

    ~Bill


    Script #1

    <?php
    if( isset($_POST['submit']))
    {
    include('2.photo.processor.php');
    $image = new SimpleImage();
    $image->load($_FILES['uploaded_image']['tmp_name']);
    $image->resizeToWidth(450);
    $image->save('newphotos/resized.jpeg');
    header('Location: 3.alumni.success.php');
    }
    ?>



    Script #2

    <?php
    if ($_FILES["file"]["error"] > 0) {
    echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
    } else {
    move_uploaded_file($_FILES["file"]["tmp_name"], "newphotos/{$_POST['lastname']}.{$_POST['firstname']}.jpeg");
    }
    ?>

    <div style="margin-top:100px; text-align:center;">
    <form method="POST" enctype="multipart/form-data">
    <input type="file" name="file"><br /><br />
    First Name<input type="text" name="firstname"><br />
    Last Name <input type="text" name="lastname"><br /><br />
    <input type="submit" value="submit">
    </form>

  2. #2
    Join Date
    Jul 2010
    Posts
    11
    Where is each script located within your website? Is script two on the same page as script one?

  3. #3
    Join Date
    Apr 2013
    Posts
    8
    No, I'm using a local server to create one script from these two temporary scripts that both resizes and renames uploaded images. When I perfect that script, I'll upload iot to my remote server for users to upload their profiles and photos. Have any ideas?

  4. #4
    Join Date
    Jul 2010
    Posts
    11
    If I were you, I would use the rename() function. The following would be your complete code:
    PHP Code:
    <?

    if( isset($_POST['submit']))
    {
    include(
    '2.photo.processor.php');
    $image = new SimpleImage();
    $image->load($_FILES['uploaded_image']['tmp_name']);
    $image->resizeToWidth(450);
    $image->save('newphotos/resized.jpeg');

    rename("newphotos/resized.jpeg""newphotos/{$_POST['lastname']}.{$_POST['firstname']}.jpeg");

    header('Location: 3.alumni.success.php');
    }

    ?>
    However, the way this code is executed is redundant because you could originally just name the resized image to the first and last name. But let me know if this works for what you need.

    Hope this helps!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles