Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 19
  1. #1
    New Coder
    Join Date
    Mar 2003
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question I Need Help With Uploading A Image Script

    Can someone please write me a good uploading a file in PHP script. I need the script to be able to upload a Image only JPEG format and i want it so that the user can rename the file so instead of it being image00001.jpg they could enter in a text box 26.jpg. I will gratefully appreciate if someone could do this for me.


    Thanks Kevin

  • #2
    New Coder
    Join Date
    Jun 2002
    Location
    hamilton,ontario
    Posts
    46
    Thanks
    0
    Thanked 0 Times in 0 Posts
    whittys.com
    Nomsane?
    That is all

  • #3
    New Coder
    Join Date
    Mar 2003
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I need a script that they user can enter in a text box what the new file name will be

  • #4
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Location
    Marion, IA USA
    Posts
    6,280
    Thanks
    4
    Thanked 83 Times in 82 Posts
    Ummm if they are uploading their file then shouldn't it already be named what they want?
    Spookster
    CodingForums Supreme Overlord
    All Hail Spookster

  • #5
    New Coder
    Join Date
    Mar 2003
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts
    No because the file is related a shopping cart i want it so that the file will be renamed to the products ID

  • #6
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Location
    Marion, IA USA
    Posts
    6,280
    Thanks
    4
    Thanked 83 Times in 82 Posts
    If the user is going to be uploading the file from their computer and you want the filename to be the product ID then why would you want to allow the user to rename the file?
    Spookster
    CodingForums Supreme Overlord
    All Hail Spookster

  • #7
    New Coder
    Join Date
    Mar 2003
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Well so they could enter the products ID

  • #8
    New Coder
    Join Date
    Mar 2003
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Can someone just give me the code??

  • #9
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Location
    Marion, IA USA
    Posts
    6,280
    Thanks
    4
    Thanked 83 Times in 82 Posts
    Is the prodcut ID already known in the system or does the user make it up right then and there?

    If it is already known in the system then don't make the user type it in because people make mistakes too easy. If the product ID is already know then automatically rename it to the proper product ID.

    If it is not known then and the user just makes it up just tell the user to name their file accordingly before they upload it.

    That would be my suggestion anyways.
    Spookster
    CodingForums Supreme Overlord
    All Hail Spookster

  • #10
    New Coder
    Join Date
    Mar 2003
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts
    It is known in the SQL DB...But the user needs to know the product name and that is in the DB as well but the picture needs to be a number.jpg for my shopping cart system to recgonize that the picture exists. If you have code for that please let me know.

  • #11
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Location
    Marion, IA USA
    Posts
    6,280
    Thanks
    4
    Thanked 83 Times in 82 Posts
    Well I am attempting to make this easier for you and steer you away from a potentially error prone system. There's no need to be rude.

    If the product information is already stored in the database then simply query the database for the information and use the product ID that you have stored as the new name for the image that the user uploads.
    Spookster
    CodingForums Supreme Overlord
    All Hail Spookster

  • #12
    New Coder
    Join Date
    Mar 2003
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I am not trying to be rude I apolgize if I seem to be. Do you have code that i can have that would do that for me.

  • #13
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Location
    Marion, IA USA
    Posts
    6,280
    Thanks
    4
    Thanked 83 Times in 82 Posts
    Code to do what? There is a function in PHP for renaming files:

    http://www.php.net/manual/en/function.rename.php
    Spookster
    CodingForums Supreme Overlord
    All Hail Spookster

  • #14
    New Coder
    Join Date
    Mar 2003
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts
    The code that will upload and rename the file to the products ID number

  • #15
    New Coder
    Join Date
    Mar 2003
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I have this

    <html>
    <body>
    <?php

    $file_dir = "/home/virtual/admin8/var/www/html/boo/"; // directory where you want file to be uploaded to
    $file_url = "http://207.44.172.156/boo"; //same directory, but as link

    foreach( $HTTP_POST_FILES as $file_name => $file_array ) {
    if (substr($file_array['type'], 0, 5)=="image") {
    echo "path: ".$file_array['tmp_name']."<br>\n";
    echo "name: ".$file_array['name']."<br>\n";
    echo "type: ".$file_array['type']."<br>\n";
    echo "size: ".$file_array['size']."<br>\n";
    if ( is_uploaded_file( $file_array['tmp_name'] ) ) {
    move_uploaded_file( $file_array['tmp_name'], "$file_dir/".$file_array['name']);
    echo "<a href=\"$file_url/$file_name\">".$file_array['name']."</a>\n\n";
    }
    } else {
    echo "File is not an image.";
    }
    }
    ?>
    <form enctype="multipart/form-data" method="post">
    <input type="hidden" name="MAX_FILE_SIZE" value="3000000000000">
    <input name="fupload" type="file"><br>
    <input type="submit" value="Send File">
    </form>
    </body>
    </html>

    But I need the renaming thing..


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

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