Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Page 1 of 2 1 2 LastLast
Results 1 to 10 of 14
  1. #1
    Member ThePhoenix2006's Avatar
    Join Date
    Mar 2005
    Location
    Michigan
    Posts
    88
    Member #
    9431
    Hey guys,

    This image uploader was made by a friend of mine, it uploads gif's just fine but not jpeg's. What I want is to just have jpegs no gifs.

    What do I need to fix to get it to upload only jpeg's and actually upload them properly?

    PHP Code:
    <?php

    define
    ("IN_LOCALAMP",true);
    include(
    "includes/common.php");

    ob_start("callback");

    if (
    $_POST['submit'] == "Upload") {

        
    $logged $_SESSION['artist_id'];
        
    $query "SELECT * FROM la_artist WHERE artist_id ='$logged'";
        
    $result mysql_query($query) or die("Query failed: ".mysql_error());
        
    $numrows mysql_num_rows($result);
        if (
    $numrows == "0") {
            echo 
    "No user<br><br>";}
        else {
        while(
    $row mysql_fetch_array($result))
        {
            
    $theid $row[artist_id];
        }

        if (
    $_FILES['files']['name']['0'] != "") {
        if ((
    $_FILES['files']['type']['0'] == "image/jpeg") OR ($_FILES['files']['type']['0'] == "image/gif")) {
        if (
    $_FILES['files']['size']['0'] <= 1048576) {
        
    $ext "jpg";
        if ( 
    $_FILES['files']['type']['0'] == "image/gif" ) { $ext "gif"; }
             
    move_uploaded_file($_FILES['files']['tmp_name']['0'], "artist_images/".$theid.".".$ext);
            
    $theurl $theid.".".$ext;
            
    $query "UPDATE la_artist SET image_url = '$theurl' WHERE artist_id = '$theid'";
           
    mysql_query($query) or die(mysql_error());
        } else {
        
    message_die("The Black Knight says that your image file is too large! It must be smaller than 1048576 bytes.");
      }
      }
        }
    }
    }
    header("Location: profile.php?p=5");
    ?>
    "Make sure the juice is worth the squeeze" ~The Girl Next Door

  2.  

  3. #2
    ljm
    ljm is offline
    Senior Member ljm's Avatar
    Join Date
    Aug 2006
    Location
    Manchester, England
    Posts
    284
    Member #
    13684
    Liked
    1 times
    It looks confusing, but why is $ext defined as a jpeg based on the size of the file, while $ext is defined as a gif based on the filetype?

    The code could be altered a bit to do the same thing:

    PHP Code:
        if (($_FILES['files']['type']['0'] == "image/jpeg") OR ($_FILES['files']['type']['0'] == "image/gif")) { 
        if (
    $_FILES['files']['size']['0'] <= 1048576) { 
        
    $ext "jpg"
        if ( 
    $_FILES['files']['type']['0'] == "image/gif" ) { $ext "gif"; } 
    becomes

    PHP Code:
    if ($_FILES['files']['type']['0'] == "image/jpeg")
    $ext "jpg"; }

    elseif (
    $_FILES['files']['type']['0'] == "image/gif")
    $ext "gif"; }

    else 
    { echo 
    "Unsupported file type."; } 
    You can add the following as the first field in the upload form, to limit the filesize.
    HTML Code:
    <input type='hidden' name='MAX_FILE_SIZE' value='x' />
    In which case, any file that is too large will have the temporary name 'none', so that can be validated in the PHP:

    PHP Code:
    if ($_FILES['file']['tmp_name']['0'] == 'none')
    { echo 
    "File too large."; }

    else

    // rest of script 

    It's replacing the existing code and of course you probably won't need to do that (my understanding of PHP isn't professional), but there might be something in there you might find useful. Probably not since I didn't go through the whole thing. :dead:

  4. #3
    Member ThePhoenix2006's Avatar
    Join Date
    Mar 2005
    Location
    Michigan
    Posts
    88
    Member #
    9431
    Hey, I got a new one that only accepts jpeg format but for some reason it still dont work.

    Here it is:

    PHP Code:
    <?php

    define
    ("IN_LOCALAMP",true);
    include(
    "includes/common.php");

    ob_start("callback");

    if (
    $_POST['submit'] == "Upload") {

        
    $logged $_SESSION['artist_id'];
        
    $query "SELECT * FROM la_artist WHERE artist_id ='$logged'";
        
    $result mysql_query($query) or die("Query failed: ".mysql_error());
        
    $numrows mysql_num_rows($result);
        if (
    $numrows == "0") {
            echo 
    "No user<br><br>";}
        else {
        while(
    $row mysql_fetch_array($result))
        {
            
    $theid $row[artist_id];
        }

        if (
    $_FILES['files']['name']['0'] != "") {
        if ((
    $_FILES['files']['type']['0'] == "image/jpeg")) {
        if (
    $_FILES['files']['size']['0'] <= 1048576) {
             
    move_uploaded_file($_FILES['files']['tmp_name']['0'], "artist_images/".$theid.".jpg");
            
    $theurl $theid.".jpg";
            
    $query "UPDATE la_artist SET image_url = '$theurl' WHERE artist_id = '$theid'";
           
    mysql_query($query) or die(mysql_error());
        } else {
        
    message_die("The Black Knight says that your image file is too large! It must be smaller than 1048576 bytes.");
      }
      }
        }
    }
    }
    header("Location: profile.php?p=5");
    ?>
    Any suggestions on this one Ljm?
    "Make sure the juice is worth the squeeze" ~The Girl Next Door

  5. #4
    WDF Staff mlseim's Avatar
    Join Date
    Apr 2004
    Location
    Cottage Grove, Minnesota
    Posts
    7,715
    Member #
    5580
    Liked
    717 times
    The directory where you are uploading your images ....

    Did you set the permissions to: 0777 ? or 777?

    You need to give the script permission to write into that directory.

    EDIT:
    Oh, never mind ... I didn't read your post close enough.
    You're using MySQL.


  6. #5
    Member ThePhoenix2006's Avatar
    Join Date
    Mar 2005
    Location
    Michigan
    Posts
    88
    Member #
    9431
    Yuppers!

    Any other suggestions guys?

    Thanks in advance.
    "Make sure the juice is worth the squeeze" ~The Girl Next Door

  7. #6
    ljm
    ljm is offline
    Senior Member ljm's Avatar
    Join Date
    Aug 2006
    Location
    Manchester, England
    Posts
    284
    Member #
    13684
    Liked
    1 times
    I'm not too sure now to be honest, since my own upload script just uploads the file to the server, not to MySQL.

    Does the site spit out any errors when you try to upload a JPEG?

  8. #7
    Member ThePhoenix2006's Avatar
    Join Date
    Mar 2005
    Location
    Michigan
    Posts
    88
    Member #
    9431
    Quote Originally Posted by ljm
    Does the site spit out any errors when you try to upload a JPEG?
    Nope it just goes and comes back to the page unchanged, which means its going through the steps just not uploading/updating it.
    "Make sure the juice is worth the squeeze" ~The Girl Next Door

  9. #8
    ljm
    ljm is offline
    Senior Member ljm's Avatar
    Join Date
    Aug 2006
    Location
    Manchester, England
    Posts
    284
    Member #
    13684
    Liked
    1 times
    Hmmm okay. I've noticed one thing though:

    PHP Code:
    $theid $row[artist_id]; 
    You need quotes around 'artist_id'. The variable isn't being given a value at the moment.

    Make that change and see if the script works.

  10. #9
    Member ThePhoenix2006's Avatar
    Join Date
    Mar 2005
    Location
    Michigan
    Posts
    88
    Member #
    9431
    Quote Originally Posted by ljm
    Make that change and see if the script works.
    I changed that but no change. Any other ideas?

    I dont get it its mind boggling.
    "Make sure the juice is worth the squeeze" ~The Girl Next Door

  11. #10
    ljm
    ljm is offline
    Senior Member ljm's Avatar
    Join Date
    Aug 2006
    Location
    Manchester, England
    Posts
    284
    Member #
    13684
    Liked
    1 times
    I've no idea if this'll work either, but I assume your artist ID is numerical (well, it should be). Take it out of the single quotes in your queries. Same with the $logged variable.

    I think if you have it in single quotes, it's actually searching the database for a value that is '$variable', not the content of the variable. Or something.

    I'm clutching at straws here. :ermm:


Page 1 of 2 1 2 LastLast

Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 03:28 AM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com