SitePoint Sponsor

User Tag List

Page 1 of 2 12 LastLast
Results 1 to 25 of 28

Hybrid View

  1. #1
    SitePoint Addict
    Join Date
    Oct 2010
    Posts
    323
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    uploading and storing image

    hello ,
    i am following an uploading and storing image tutorial, but a default message to show that you have to select an image is not showing(echo "Please select an image."
    the code so far is below thanks


    PHP Code:
        <?php require_once("include/session.php");?>
        <?php require_once("include/dataconnect.php");?>
        <?php require_once("include/functions.php");?>
        <?php include("include/header.php");?>
        <div>
        <!--<form action='tindex5.php' method='Post' enctype='multipart/form-data'class='rl'>-->
        <form action='affiliatestore.php' method='Post' enctype='multipart/form-data'class='rl'>
            <div>
            <label for='name' class='fixedwidth'>name</label>
            <input type='text' name='name' id='name'/>
            </div>
            
            <div>
            <label for='namelink' class='fixedwidth'>namelink</label>
            <input type='text' name='username' id='username'/>
            </div>
            
            <div>
            <label for='image' class='fixedwidth'>image</label>
            <input type='file' name='image' id='image'/>
            </div>
            
            <div>
            <label for='imagelink' class='fixedwidth'>imagelink</label>
            <input type='text' name='imagelink' id='imagelink'/>
            </div>
            
            <div>
            <label for='base' class='fixedwidth'>base</label>
            <input type='text' name='base' id='base'/>
            </div>
            
            <div>
            <label for='baselink' class='fixedwidth'>baselink</label>
            <input type='text' name='baselink' id='baselink' />
            </div>
                
            <div class='buttonarea'>
                    <p>
                    <input type='submit' name='submit' value='submit'>
                    </p>
                    </div>
        </form>
        </div>
        <?php
        
    //file properties
        
    $file$_FILES['image']['tmp_name'];
        if (!isset(
    $file))
        echo 
    "Please select an image.";
    else
    {
    $image addslashes(file_get_contents($_FILES['image']['tmp_name']));
    $image_name addslashes($_FILES['image']['name']);
    $image_size getimagesize($_FILES['image']['tmp_name']);
    if (
    $image_size==FALSE)
    echo 
    "Thats not an image";
    else
    {
    }

    }
    ?>
    <?php 
    include("include/footer.php");?>

  2. #2
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    I think that is caused by poor bracketing made worse by a lack of indenting ...

    PHP Code:
        if (!isset($file)) {
        echo 
    "Please select an image.";
        }else{
        
    // get on with it 

        

    I only try and get away with stuff like that when there is no else clause:

    PHP Code:

      
    if( $loggedin )
              
    showlogoutbutton(); 

  3. #3
    SitePoint Addict
    Join Date
    Oct 2010
    Posts
    323
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    @cups thanks, please i have followed the tutorial but the image upload is not displaying

    this is the code
    affiliatestore.php

    PHP Code:
    <?php require_once("include/session.php");?>
    <?php 
    require_once("include/dataconnect.php");?>
    <?php 
    require_once("include/functions.php");?>
    <?php 
    include("include/header.php");?>
    <div>
    <!--<form action='tindex5.php' method='Post' enctype='multipart/form-data'class='rl'>-->
    <form action='affiliatestore.php' method='Post' enctype='multipart/form-data'class='rl'>
        <div>
        <label for='name' class='fixedwidth'>name</label>
        <input type='text' name='name' id='name'/>
        </div>
        
        <div>
        <label for='namelink' class='fixedwidth'>namelink</label>
        <input type='text' name='namelink' id='namelink'/>
        </div>
        
        <div>
        <label for='image' class='fixedwidth'>image</label>
        <input type='file' name='image' id='image'/>
        </div>
        
        <div>
        <label for='imagelink' class='fixedwidth'>imagelink</label>
        <input type='text' name='imagelink' id='imagelink'/>
        </div>
        
        <div>
        <label for='base' class='fixedwidth'>base</label>
        <input type='text' name='base' id='base'/>
        </div>
        
        <div>
        <label for='baselink' class='fixedwidth'>baselink</label>
        <input type='text' name='baselink' id='baselink' />
        </div>
            
        <div class='buttonarea'>
                <p>
                <input type='submit' name='submit' value='submit'>
                </p>
                </div>
    </form>
    </div>
    <?php
    //if (isset($_POST['submit'])) {
    //file properties
    //$file= $_FILES['image']['tmp_name'];
    if (!isset($_FILES['image']))
            {
            echo 
    "Please select an image.";
            }
    else
                {
        if (isset(
    $_POST['submit']))
                      {
                        
    $image mysql_real_escape_string(file_get_contents($_FILES['image']['tmp_name']));
                        
    $image_name = ($_FILES['image']['name']);
                        
    $namelink mysql_real_escape_string(htmlentities(strip_tags($_POST['namelink'])));
                        
    $imagelink mysql_real_escape_string(htmlentities(strip_tags($_POST['imagelink'])));
                        
    $base mysql_real_escape_string(htmlentities(strip_tags($_POST['base'])));
                        
    $baselink mysql_real_escape_string(htmlentities(strip_tags($_POST['baselink'])));
                        
    $image_size getimagesize($_FILES['image']['tmp_name']);
                    }
    if (
    $image_size==FALSE)
                    echo 
    "Thats not an image";
    else
                    {
    if(!
    $insert mysql_query("

                        INSERT INTO store VALUES ('','
    $image_name','$namelink','$image','$imagelink','$base','$baselink')

                            "
    ))
                            echo
    "Problem uploading image";
    else
                    {
                        
    $lastid mysql_insert_id();
                        echo
    "Image uploaded.<p />Your image:<p /><img src=getaffiliatestore.php?id=$lastid>";
                    }
                    }

                    }
    ?>
    getaffiliatestore.php

    PHP Code:
    <?php require_once("include/session.php");?>
    <?php 
    require_once("include/dataconnect.php");?>
    <?php 
    require_once("include/functions.php");?>
    <?php 
    include("include/header.php");?>
    <?php

    $id
    =  mysql_real_escape_string($_REQUEST['id']);
    $image mysql_query("SELECT * FROM store WHERE id=$id");
    $image mysql_fetch_assoc($image);
    $image $image['image'];
    header("Content-type: image/jpeg");
    echo 
    $image;

    ?>

  4. #4
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    hello ,
    i am following an uploading and storing image tutorial, but a default message to show that you have to select an image is not showing echo("Please select an image."
    So, is that issue now fixed?

  5. #5
    SitePoint Addict
    Join Date
    Oct 2010
    Posts
    323
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    yes the select an image is now fixed, just that, after uploading the image, and the image is meant to show.but the image does not show

  6. #6
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    Carefully read the manual pages on uploads.

    Then use var_dump($_FILES) to look at the value for 'error', if that is greater than 0 then that should give you a better idea of what caused the failure.

  7. #7
    SitePoint Addict
    Join Date
    Oct 2010
    Posts
    323
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    @cups the error is 0 but i dont why the page is not retirving,

    when i <?php print_r($_FILES);?>

    i had

    Array ( [image] => Array ( [name] => id.jpeg [type] => image/jpeg [tmp_name] => /private/var/tmp/phpZUl2tj [error] => 0 [size] => 463762 ) ) ,

    this is the page that is supposed to display the image


    PHP Code:
     <?php print_r($_FILES);?>
        <div>
        <!--<form action='tindex5.php' method='Post' enctype='multipart/form-data'class='rl'>-->
        <form action='affiliatestore.php' method='Post' enctype='multipart/form-data'class='rl'>
            <div>
            <label for='name' class='fixedwidth'>name</label>
            <input type='text' name='name' id='name'/>
            </div>
            
            <div>
            <label for='namelink' class='fixedwidth'>namelink</label>
            <input type='text' name='namelink' id='namelink'/>
            </div>
            
            <div>
            <label for='image' class='fixedwidth'>image</label>
            <input type='file' name='image' id='image'/>
            </div>
            
            <div>
            <label for='imagelink' class='fixedwidth'>imagelink</label>
            <input type='text' name='imagelink' id='imagelink'/>
            </div>
            
            <div>
            <label for='base' class='fixedwidth'>base</label>
            <input type='text' name='base' id='base'/>
            </div>
            
            <div>
            <label for='baselink' class='fixedwidth'>baselink</label>
            <input type='text' name='baselink' id='baselink' />
            </div>
                
            <div class='buttonarea'>
                    <p>
                    <input type='submit' name='submit' value='submit'>
                    </p>
                    </div>
        </form>
        </div>
        <?php
        
    //file properties
        //$file= $_FILES['image']['tmp_name'];
        
    if (!isset($_FILES['image'])) {
        echo 
    "Please select an image.";
        }
    else
    {
                        
    $image mysql_real_escape_string(file_get_contents($_FILES['image']['tmp_name']));
                        
    $image_name = ($_FILES['image']['name']);
                        
    $namelink mysql_real_escape_string(htmlentities(strip_tags($_POST['namelink'])));
                        
    $imagelink mysql_real_escape_string(htmlentities(strip_tags($_POST['imagelink'])));
                        
    $base mysql_real_escape_string(htmlentities(strip_tags($_POST['base'])));
                        
    $baselink mysql_real_escape_string(htmlentities(strip_tags($_POST['baselink'])));
                        
    $image_size getimagesize($_FILES['image']['tmp_name']);
    if (
    $image_size==FALSE){
    echo 
    "Thats not an image";
    }
    else
    {
    if(!
    $insert mysql_query("

                        INSERT INTO store VALUES ('','
    $image_name','$namelink','$image','$imagelink','$base','$baselink')

                            "
    ))
                            echo
    "Problem uploading image";
                            else
                    {
                        
    $lastid mysql_insert_id();
                        echo 
    "Image uploaded.<p />Your image:<p /><img src=getaffiliatestore.php?id=$lastid>";
                    }
    }

    }
    ?>
    <?php 
    include("include/footer.php");?>

  8. #8
    SitePoint Addict
    Join Date
    Oct 2010
    Posts
    323
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    image upload php/mysql

    hello i have asked this question may i be i did not structure the question well

    i am trying to upload(mysql database) and display an image following a tutorial , my image has not displayed, please could someone have a look where i am wrong,
    favorite

    the two codes i am trying to use are below

    PHP Code:
     <!--<?php print_r($_FILES);?>-->
        <div>
        <!--<form action='tindex5.php' method='Post' enctype='multipart/form-data'class='rl'>-->
        <form action='affiliatestore.php' method='Post' enctype='multipart/form-data'class='rl'>
            <div>
            <label for='name' class='fixedwidth'>name</label>
            <input type='text' name='name' id='name'/>
            </div>

            <div>
            <label for='namelink' class='fixedwidth'>namelink</label>
            <input type='text' name='namelink' id='namelink'/>
            </div>

            <div>
            <label for='image' class='fixedwidth'>image</label>
            <input type='file' name='image' id='image'/>
            </div>

            <div>
            <label for='imagelink' class='fixedwidth'>imagelink</label>
            <input type='text' name='imagelink' id='imagelink'/>
            </div>

            <div>
            <label for='base' class='fixedwidth'>base</label>
            <input type='text' name='base' id='base'/>
            </div>

            <div>
            <label for='baselink' class='fixedwidth'>baselink</label>
            <input type='text' name='baselink' id='baselink' />
            </div>

            <div class='buttonarea'>
                    <p>
                    <input type='submit' name='submit' value='submit'>
                    </p>
                    </div>
        </form>
        </div>
        <?php
        
    //file properties
        //$file= $_FILES['image']['tmp_name'];
        //if (!isset($_FILES['image'])) {
        
    if (!isset($_POST['submit'])) {
        echo 
    "Please select an image.";
        }
    else
    {
                        
    $image mysql_real_escape_string(file_get_contents($_FILES['image']['tmp_name']));
                        
    $image_name = ($_FILES['image']['name']);
                        
    $namelink mysql_real_escape_string(htmlentities(strip_tags($_POST['namelink'])));
                        
    $imagelink mysql_real_escape_string(htmlentities(strip_tags($_POST['imagelink'])));
                        
    $base mysql_real_escape_string(htmlentities(strip_tags($_POST['base'])));
                        
    $baselink mysql_real_escape_string(htmlentities(strip_tags($_POST['baselink'])));
                        
    $image_size getimagesize($_FILES['image']['tmp_name']);
    if (
    $image_size==FALSE){
    echo 
    "Thats not an image";
    }
    else
    {
    if(!
    $insert mysql_query("

                        INSERT INTO store VALUES ('','
    $image_name','$namelink','$image','$imagelink','$base','$baselink')

                            "
    ))
                            echo
    "Problem uploading image";
                            else
                    {
                        
    $lastid mysql_insert_id();
                        
    //echo $lastid;
                        
    echo "Image uploaded.<p />Your image:<p /><img src=getaffiliatestore.php?id=$lastid>";
                    }
    }

    }
    ?>
    and the second code affiliatestore.php

    PHP Code:
    $id =  mysql_real_escape_string($_REQUEST['id']);
    //echo $id;
    $image mysql_query("SELECT * FROM store WHERE id=$id");
    $image mysql_fetch_assoc($image);
    $image $image['image'];
    $nimage $image['name'];
    //echo $nimage;
    header("content-type:image/jpeg");
    echo 
    $image;
    ?> 
    thanks

  9. #9
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    73 Post(s)
    Tagged
    0 Thread(s)
    i highly advise against storing the image data directly in the database.

    It's possible that while real_escape_string'ing it, you're corrupting the image data.

    Have you checked your database to make sure things are being entered? INSERT...VALUES without field names makes me leery.
    Never grow up. The instant you do, you lose all ability to imagine great things, for fear of reality crashing in.

  10. #10
    SitePoint Addict
    Join Date
    Oct 2010
    Posts
    323
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    the values are being entered in the database including the image, but i have tried everything to make it display but its not .

  11. #11
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,219
    Mentioned
    153 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by lostty84 View Post
    the values are being entered in the database including the image, but i have tried everything to make it display but its not .
    What is the type of your image column? Is it a blob?

  12. #12
    SitePoint Addict
    Join Date
    Oct 2010
    Posts
    323
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    yes the image column is blob, i have also commented out the header but same result

  13. #13
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    73 Post(s)
    Tagged
    0 Thread(s)
    well the fact that you havent put quotes around your src attribute in your image tag might have something to do with it...
    beyond that, have you tried commenting out the header line and viewing getaffiliatestore.php directly?
    Never grow up. The instant you do, you lose all ability to imagine great things, for fear of reality crashing in.

  14. #14
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    So, does the image actually upload?
    Where do you move it to?
    What errors are being shown?

  15. #15
    SitePoint Addict
    Join Date
    Oct 2010
    Posts
    323
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    the image uploads in the database,
    i try to call the image on the affiliatestore.php
    no error is shown

  16. #16
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    You are storing the image in the db? I have no experience of that, sorry.

    I'm out.

  17. #17
    SitePoint Addict
    Join Date
    Oct 2010
    Posts
    323
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    thanks for the effort

  18. #18
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,219
    Mentioned
    153 Post(s)
    Tagged
    0 Thread(s)
    I do agree with Cups, that storing it in a database is a mistake. However, since that is what you want, what type of field is your image column?
    Also try changing
    PHP Code:
    $image $image['image']; 
    To
    PHP Code:
    $image stripslashes($image['image']); 

  19. #19
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,219
    Mentioned
    153 Post(s)
    Tagged
    0 Thread(s)
    , I think I spotted something
    PHP Code:
    $id =  mysql_real_escape_string($_REQUEST['id']); 
    //echo $id; 
    $image mysql_query("SELECT * FROM store WHERE id=$id"); 
    $image mysql_fetch_assoc($image); 
    $image $image['image']; 
    $nimage $image['name']; 
    //echo $nimage; 
    header("content-type:image/jpeg"); 
    echo 
    $image
    ?> 
    Take a very close look at your variable names. You are using $image, in all sorts of different meanings, constantly overwriting its value. First it is the result of mysql_query, then the result of mysql_fetch_assoc, then it is the image column value. Try giving it a single purpose, maybe something like so:
    PHP Code:
    $id =  mysql_real_escape_string($_REQUEST['id']); 
    //echo $id; 
    $imageQuery mysql_query("SELECT * FROM store WHERE id=$id"); 
    $imageResult mysql_fetch_assoc($imageQuery); 
    $image $imageResult['image']; 
    $nimage $imageResult['name']; 
    //echo $nimage; 
    header("content-type:image/jpeg"); 
    echo 
    $image
    ?> 
    Also, make sure you have ABSOLUTELY NO WHITESPACE at the end of your PHP file, that will screw up the header output.

  20. #20
    SitePoint Addict
    Join Date
    Oct 2010
    Posts
    323
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    i have tried it , still not showing the image

  21. #21
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,219
    Mentioned
    153 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by lostty84 View Post
    i have tried it , still not showing the image
    If you add var_dump($imageResult), what do you get as the output (may need to comment out the header() call)

  22. #22
    SitePoint Addict
    Join Date
    Oct 2010
    Posts
    323
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    this is the output i had
    Notice: Undefined variable: imageResult in /Users/mgltd/Sites/reacheasy/affiliatestore.php on line 6 NULL

  23. #23
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,219
    Mentioned
    153 Post(s)
    Tagged
    0 Thread(s)
    Using
    PHP Code:
    $id =  mysql_real_escape_string($_REQUEST['id']); 
    //echo $id; 
    $imageQuery mysql_query("SELECT * FROM store WHERE id=$id"); 
    $imageResult mysql_fetch_assoc($imageQuery); 
    $image $imageResult['image']; 
    $nimage $imageResult['name']; 
    //echo $nimage; 
    //header("content-type:image/jpeg"); 
    var_dump($imageResult);
    echo 
    $image
    ?> 
    Produced Undefined variable: imageResult and the value of NULL?
    That means it couldn't find the data in your table for the $id given. So it never returned an entry for the image.

  24. #24
    SitePoint Addict
    Join Date
    Oct 2010
    Posts
    323
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    but the database is showing that an image has been uploaded

  25. #25
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,219
    Mentioned
    153 Post(s)
    Tagged
    0 Thread(s)
    What is the ID of that record?


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
  •