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.

Results 1 to 3 of 3
  1. #1
    Member ThePhoenix2006's Avatar
    Join Date
    Mar 2005
    Location
    Michigan
    Posts
    88
    Member #
    9431
    Hey guys,

    I am working on this image uploader that my friend made. For some reason the gif's work just fine but... the jpg's do not.

    Here is my code: (When you change "jpg" in the code to "gif", the script works just fine.)



    PHP Code:
    <?php
    //print_r($_FILES);
    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/jpg") {
        if (
    $_FILES['files']['size']['0'] <= 1048576) { $ext "jpg"; }
        if (
    $_FILES['files']['type']['0'] == "image/jpg" ) { $ext "jpg"; }
             
    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("Your image file is too large! It must be smaller than 1MB.");
    }
    }
    }
    }
    header("Location: profile.php?p=5");
    ?>
    And Here is what the results are attempting with a JPG:

    Array ( [files] => Array ( [name] => Array ( [0] => 438465774_l.jpg ) [type] => Array ( [0] => image/pjpeg ) [tmp_name] => Array ( [0] => C:\Program Files\xampp\tmp\phpE1.tmp ) [error] => Array ( [0] => 0 ) [size] => Array ( [0] => 74408 ) ) )


    Where is the P coming from? Shoudn't it be image/jpeg??

    --------------------------------------------------------------------------------------------------------------

    Here are the results with a GIF:

    Array ( [files] => Array ( [name] => Array ( [0] => Untitled-1.gif ) [type] => Array ( [0] => image/gif ) [tmp_name] => Array ( [0] => C:\Program Files\xampp\tmp\phpE2.tmp ) [error] => Array ( [0] => 0 ) [size] => Array ( [0] => 42918 ) ) )
    "Make sure the juice is worth the squeeze" ~The Girl Next Door

  2.  

  3. #2
    Member ThePhoenix2006's Avatar
    Join Date
    Mar 2005
    Location
    Michigan
    Posts
    88
    Member #
    9431
    OK I figured out my previous problem. I now have the uploader working, naming and placing the files correctly, and can limit upload image size.
    But I cant get it to (Echo) display a warning that file size is to big.

    Near working code below


    PHP Code:
    <?php
    //print_r($_FILES);
    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/pjpeg") {$ext ".jpg";
        if (
    $_FILES['files']['size']['0'] <= 100000)  // Size limitation works but no error message.
            
    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("Your image file is too large! It must be smaller than 1MB.");
    }
    }
    }
    }
    header("Location: profile.php?p=5");
    ?>
    "Make sure the juice is worth the squeeze" ~The Girl Next Door

  4. #3
    Senior Member
    Join Date
    May 2003
    Location
    UK
    Posts
    2,354
    Member #
    1326
    Shouldnt

    PHP Code:
    message_die("Your image file is too large! It must be smaller than 1MB."); 
    Be
    PHP Code:
    die("Your image file is too large! It must be smaller than 1MB."); 
    Although, you may still want the script to redirect, so maybe change it to echo with no exit.


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 04:23 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com