view image |
[eluser]shiva478[/eluser]
Hi I'm new to php and codeigniter. I was doing a tutorial on file uploading class in http://ellislab.com/codeigniter/user-gui...ading.html I was able to insert the image path into my database. The only problem I have is that I want to view the images on the view and I'm not sure how I go about doing that. This is my upload controller Code: <?php This is my upload_model Code: <?php This is my upload_form Code: <html> This is my upload_success view Code: <html> This is my view Code: <html>
[eluser]DarkManX[/eluser]
1. If you are new to php, dont start with a framework, just code in pure php without any frameworks. Starting with ci without knowing php you will just copy & paste the tutorial code without knowing whats really going on. 2. You got a systax error in your view, you forgot ";". 3. If (2) is not the source of trouble, that is the output when you call /upload/view?
[eluser]shiva478[/eluser]
1. I'm trying to kill two birds with one stone. Before I posted my problem I did go through the coding so I do know what is more or less happening 2. The ; wasn't the problem. 3. When I call /upload/view I get the content, I don't get any images. I have tried to get the images by putting Code: <?php echo $row->image_path; ?> Quote:C:/wamp/www/tutorial/uploads/
[eluser]LuckyFella73[/eluser]
You only save the image path into db not the image name. Your insert should look like: Code: $insert_data = array( In your view echo path and filename. You could even just save the filename and set the path in a config file. If you change the path in future (could happen) it's easier to change the config instead of all the rows in your db.
[eluser]shiva478[/eluser]
@luckyfella73 I did what you said and my image doesn't load. I get the little box with a torn edge like one usually gets when you can't view a picture. I changed Quote:<img src="<?php echo $row->image_path ?>" /> into Quote:<img src="<?php echo $row->filename; ?>" />
[eluser]srpurdy[/eluser]
[quote author="shiva478" date="1345652369"]@luckyfella73 I did what you said and my image doesn't load. I get the little box with a torn edge like one usually gets when you can't view a picture. I changed Quote:<img src="<?php echo $row->image_path ?>" /> into Quote:<img src="<?php echo $row->filename; ?>" />[/quote] you need both the image path and the image filename. Normally I don't save paths into the db. I think it's kind of pointless, and if you ever change folder structures that's just a huge pain. Better off making a config file with the image path in it, and only saving the file name into the db. $config['image_file_path'] = 'path/to/myimages/'; make sure that config file is loaded in the controller. (or autoloaded if it's a global thing) Then you can just do Code: <img src="<?php echo base_url() . $this->config->item('image_file_path') . $row->filename;?>" alt="" /> Unless of course there is some reason you need the path in the db. Like if the paths will be different. But even then you don't really need to save the path in the db. Like say you had a folder for each user or something. You can have a base patth to where all those folders are, and you can use a query to get the folder name based on username or something like that. So pretty much avoiding having to save it into the db for no reason really. DarkManX does make a good suggestion about trying pure php, but CI is probably the easier framework to get to grips with so that's a good thing. Just remember the easier way is not always the best way to do something. and other times it can be the complete opposite of that.
[eluser]DarkManX[/eluser]
[quote author="shiva478" date="1345641272"]1. I'm trying to kill two birds with one stone. Before I posted my problem I did go through the coding so I do know what is more or less happening[/quote] You cant learn to play football without being able to run. i suggest you - once more - to practice on some pure php stuff.
[eluser]LuckyFella73[/eluser]
@shiva478 if you managed it to upload your file and make an entry into your database you shouldn't giv up - my opinion. Please check the following points before going on: 1. is you file really uploaded (look into your folder to get sure) 2. is the entry in your db made and the values correct (filename is the same like the uploaded file)? If yes come back here and we get you image to display - hopefully
[eluser]shiva478[/eluser]
@luckyfella73 1. yep the file is uploaded to the folder 2. yep the db entry and the filename are the same
[eluser]LuckyFella73[/eluser]
ok that sounds good! If you put that into your view you should see the image: Code: <img src="<?php echo $row->image_path.'/'.$row->filename; ?>" /> I assume that you named the new column in your tabel "filename" where you save the upload files name. Hope that works |
Welcome Guest, Not a member yet? Register Sign In |