how to view an image to the upload directory?

This is a discussion on "how to view an image to the upload directory?" within the PHP Forum section. This forum, and the thread "how to view an image to the upload directory? are both part of the Program Your Website category.



Go Back   Webforumz.com > Main Forums > Program Your Website > PHP Forum

Notices


Reply
 
LinkBack Thread Tools
  #1 (permalink)  
Old Nov 11th, 2007, 16:35
New Member
Join Date: Nov 2007
Location: general santos
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
how to view an image to the upload directory?

how to view an image to the upload directory?

i am using this <img src=$row[image]> correct me if im wrong here...

below is my php code for my upload.php but the problem is how to view the image?

hope anyone can help me..


PHP: Select all

  <?php 
       
if (array_key_exists('_submit_check'$_POST)){
            
            
$max_image_width380;
            
$max_image_height600;
            
$max_image_size64 1024;
            
$image_type =  array("gif","jpg""jpeg");
            
        if (isset(
$_FILES["userfile"])) {
                
                if (
is_uploaded_file($_FILES["userfile"]["tmp_name"])) {
                
                        
$image_name $_FILES["userfile"]["tmp_name"];
                        
$ext substr($_FILES["userfile"]["name"], 
                        
strrpos($_FILES["userfile"]["name"], "."));
                
                if (
filesize($image_name) > $max_image_size) {
                
                        
$error "Error: File size > 64K.";
                        
                        } elseif (!
in_array($ext$image_type)) {
                        
                        
$error "Error: Invalid file type.";
                        
                } else {
                
                        
$image_size GetImageSize($image_name);
                 
                 if ((
$image_size) && ($image_size[0] < $max_image_width) && ($image_size[1] < $max_image_height)) {
                 
                 
$uploaddir "/home/simply22/public_html/admin/cj/";
                 
                if (
move_uploaded_file($_FILES["userfile"]["tmp_name"], $uploaddir 
                                        
$_FILES["userfile"]["name"])) 
                {
                            
$msg "The file has been uploaded, and your information has been added to the directory";
                            } else {
                            
$error "Error: moving fie failed.";
                            }
                            } else {
                            
$error "Error: invalid image properties.";
                            }
                            }
                            } else {
                            
$error "Error: empty file.";
                            }

                        
$couponstore=$_POST['couponstore'];
                        
$coupontitle=$_POST['coupontitle'];
                        
$website=$_POST['website'];
                        
$userfile=$_FILES['image'];
                        
$image_name=$_POST['image_name'];
                        
$image_type=$_POST['image_type'];
                        
$image_size=$_POST['image_size'];
                        
$detail=$_POST['detail'];
                        
$days=$_POST["days"];
                        
$date=$_POST['date'];
                        
$feat=$_POST['feat'];
                        
$sto_cat=$_POST['sto_cat'];
                
            
$sql="INSERT INTO deals (couponstore, coupontitle, image, image_name, image_type, image_size, website, detail, days, date, feat, sto_cat) values('$couponstore', '$coupontitle', '$userfile', '$image_name', '$image_type', '$image_size','$website', '$detail', '$days', '$date', '$feat', '$sto_cat')";
            
$result=mysql_query($sql,$dbh) or die(mysql_error()); 
            } 
                } 
        
?>
Reply With Quote

  #2 (permalink)  
Old Nov 11th, 2007, 17:45
marSoul's Avatar
Moderator
Join Date: Sep 2007
Location: Tehran - Iran
Age: 28
Posts: 409
Blog Entries: 2
Thanks: 3
Thanked 4 Times in 4 Posts
Send a message via MSN to marSoul Send a message via Yahoo to marSoul
Re: how to view an image to the upload directory?

i think u should use this code in HTML if u want to use php :

<img src="<?php echo $row[image] ?>">
__________________
Designing For Communicating
Website : http://www.datisdesign.com
Weblog : http://blog.datisdesign.com

Last Blog Entry: Throughout IRAN (Dec 10th, 2007)
Reply With Quote
  #3 (permalink)  
Old Nov 11th, 2007, 17:48
Marc's Avatar
Moderator

SuperMember
Join Date: Apr 2007
Location: Scotland, UK
Age: 15
Posts: 1,650
Thanks: 0
Thanked 8 Times in 8 Posts
Send a message via MSN to Marc Send a message via Skype™ to Marc
Re: how to view an image to the upload directory?

Yep, you must have the <?php ?> in there.... Also if you are using xHTML you need to do this:

HTML: Select all
<img src="<?php echo $row[image] ?>" alt="" />
PS... You have to have alt="" in there to make it validate with HTML!
Reply With Quote
  #4 (permalink)  
Old Nov 11th, 2007, 18:17
New Member
Join Date: Nov 2007
Location: general santos
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Re: how to view an image to the upload directory?

thanks for the response, but nothing happens here no image have shown..
Reply With Quote
  #5 (permalink)  
Old Nov 11th, 2007, 21:48
marSoul's Avatar
Moderator
Join Date: Sep 2007
Location: Tehran - Iran
Age: 28
Posts: 409
Blog Entries: 2
Thanks: 3
Thanked 4 Times in 4 Posts
Send a message via MSN to marSoul Send a message via Yahoo to marSoul
Re: how to view an image to the upload directory?

if ur file r online, please send the links...
__________________
Designing For Communicating
Website : http://www.datisdesign.com
Weblog : http://blog.datisdesign.com

Last Blog Entry: Throughout IRAN (Dec 10th, 2007)
Reply With Quote
  #6 (permalink)  
Old Nov 12th, 2007, 04:27
Rakuli's Avatar
SuperMember

SuperMember
Join Date: Sep 2007
Location: Australia
Age: 24
Posts: 956
Blog Entries: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Re: how to view an image to the upload directory?

$row doesn't actually appear to be anything....

You won't be able to simple echo out the $_FILES['file']['name']..

You need to know where in relation to your webpage root directory your uploaded image will be..

Then you would be able to echo using

HTML: Select all
<img src="from/http/to/here/<?php echo $_FILES['file']['name']; ?>" />
If you don't do that, php is echoing out something like

home/user/public_html/www/image.jpg which obviously is not right relative to your webpages root directory.

Hope that helps,
Last Blog Entry: The wannabe juggler's quest (Oct 27th, 2007)
Reply With Quote
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Example of Image Upload hanusoft Classic ASP 1 Sep 20th, 2007 10:39
upload image webdeveloper Classic ASP 0 Aug 3rd, 2007 07:54
Setting the directory to upload an image php djme PHP Forum 2 Jan 11th, 2006 15:39
Image Upload/Delete ekendricks Classic ASP 5 Nov 18th, 2003 12:36


All times are GMT. The time now is 07:25.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43