Webforumz's RSS FeedRSS Webforumz RegistrationRegister Contact Webforumz StaffContact

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.


 Subscribe in a reader

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

Notices




Reply
 
LinkBack Thread Tools
  #1  
Old Nov 11th, 2007, 17: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()); 
            } 
                } 
        
?>
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #2  
Old Nov 11th, 2007, 18:45
Reputable Member
Join Date: Sep 2007
Location: Tehran - Iran
Age: 29
Posts: 433
Blog Entries: 2
Thanks: 7
Thanked 7 Times in 7 Posts
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)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #3  
Old Nov 11th, 2007, 18:48
Marc's Avatar
Staff Manager

SuperMember
Join Date: Apr 2007
Location: Scotland, UK
Posts: 1,871
Thanks: 1
Thanked 23 Times in 23 Posts
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!
__________________
Thanks
Marc
Staff Manager - Want to be a Moderator? PM me.

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #4  
Old Nov 11th, 2007, 19: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..
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #5  
Old Nov 11th, 2007, 22:48
Reputable Member
Join Date: Sep 2007
Location: Tehran - Iran
Age: 29
Posts: 433
Blog Entries: 2
Thanks: 7
Thanked 7 Times in 7 Posts
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)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #6  
Old Nov 12th, 2007, 05: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)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
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 11:39
upload image webdeveloper Classic ASP 0 Aug 3rd, 2007 08:54
Setting the directory to upload an image php djme PHP Forum 2 Jan 11th, 2006 16:39
Image Upload/Delete ekendricks Classic ASP 5 Nov 18th, 2003 13:36


All times are GMT. The time now is 06:08.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0 RC8