I used symfony 1.4 to make a basic form that contains an image upload widget, (which uploads the image just fine) but when I try to echo the image later on it doesn't show.
This is the code I use to (try to) output my image:
<img src="<?php echo sfConfig::get('sf_upload_dir').'\\'.$post->getImagename() ?>" />
A quick peek at firebug shows me that firefox "failed to load given url". but if I copy & paste the url into the address bar it loads the image just fine.
(Please note, I am developing on a windows environment and my project directory contains no spaces.)
Can anyone explain to me why this happens or what I am doing wrong?
You shouldn't use the sf_upload_dir key because it returns the full path to the image inside the webserver. Like: c:\website\project\web\uploads.
You should use sf_upload_dir_name instead, which returns the path to the uploads folder inside the web folder.
Try:
<img src="/<?php echo sfConfig::get('sf_upload_dir_name').'/'.$post->getImagename() ?>" />
Related
I defined a constant:
define('ROOT_URL', dirname(__FILE__));
I am using it with a second part of a path to call on a png image.
<img src="<?php echo ROOT_URL ?>/images/folder1/logo-black.png" nosend="1" border="none" width="129" height="34" />
Image returns broken and my path is not as it should be. (But still when I link it, it shows me a image).
It's like:
C:\wamp64\www\email-signatures/images/folder1/logo-black.png"
It's with \ and / .
What am I doing wrong?
If you pass the browser an address like this C:\wamp64\www\email-signatures/images/folder1/logo-black.png it will look on the other guys PC for that folder and file. Remember you are passing text (HTML) to a browser on someone elses PC, for the browser to interpret and paint on that other PC's Screen. You need to pass a URL so the browser knows to go to your WebServer for the image.
You could use the whole http://domain........ but if you just use the relative folder name, even if you move this code to another domain, it should still work just fine.
So assuming the images folder is just below your DocumentRoot try
<img src="images/folder1/logo-black.png" nosend="1" border="none" width="129" height="34" />
I am trying to display an image that I manually uploaded using the cPanel File Manager (or Eclipse Import), using the following in a View:
<img src="/app/public/images/logos/DoesNotShow.jpg">
and it does NOT show up. When I take another jpg that already existed:
<img src="/app/public/images/logos/DoesShow.jpg">
it displays perfectly. If I download DoesShow.jpg from the cPanel File Manager, rename it WillThisShow.jpg, and then upload (using cPanel File Manger) WillThisShow.jpg to the same folder, and put the following in the view:
<img src="/app/public/images/logos/WillThisShow.jpg">
it also does NOT display.
I inspected the non-uploaded and the uploaded, and the full correct path was shown for both.
Any ideas?
Make sure you have sent your base url $config['base_url'] = 'http://example.com/' end it with / so you dont have to use it on view. Also make sure you images are outside of the application
application
app
app > public
system
index.php
config/autoload the url helper.
Then on the image
<img src="<?php echo base_url('app/public/images/logos/WillThisShow.jpg');?>"
Use this If your baseUrl not ending with / eg: http://demo.com then
<img src="<?php echo base_url();?>/app/public/images/logos/DoesNotShow.jpg">
OR
Change the permission to 0644
I am using PHP to upload images in my web application. The images are stored in some directory on the server while their paths are stored directly in MySQL database.
The upload goes very well and images get in the folder but the problem is accessing thoses images with their path field stored in the database : i am not yet able to find the correct form of the path i should use, now am using the realPath and dirname functions to help me get the path so finally an example of path is C:\wamp\www\webroot\img.png (since am on Windows using wampserver) So when i do something like :
<img src="$image->path" />
i get no image shown in the browser and when i inspect it i get the expected code like :
<img src="C:\wamp\www\webroot\img.png" />
which means that this path format is not correct to show the image.
I have tried many things : i took the same path and acced it with the browser and it showed me the image (with the file protocol automatically) so i added file:// to the image path but nothing was new. I have also tried to acces it as a web url and with that it goes will for example it shows the image when putting
localhost/webroot/img.png
But what i need exactly is being able to store and retrive the image file again. So is it a file system probelm ? is the code platform independant ?
I will be very grateful for any help
Thank you.
You can't show an image with its path, but with its URL.
In PHP, we use to save the filename only in MySQL and after, you display the image with <img src="path/to/img/<?php echo $image->filename; ?>" />
That's all!
Add the file protocal to your path.
<img src="file:///<?php echo $image->path; ?>" />.
The best thing you could have to done is save the image in a folder inside your project/website folder. Then save the path to the image from the root folder in the DB.
Example: I uploaded a an image of filename "image.png" inside "Img" folder in the Website Root Folder. Then I will save "Img/image.png" inside my DB.
So anytime I want to reference the image, I will just use
<img src="/<?php echo $image->path; ?>" />
Or
<img src="<?php echo $image->path; ?>" />
Sorry for wasting your time, i have solved the problem. It was an issue with how my application is accessed. It should be accessed from only a directory called web so every path should be referenced from that directory !!.
I have a main domain that users can upload images to which are then viewed in a slider so multiple images (sometimes up to 50) are loaded by the page on loading. I am trying to access the same images on a subdomain but it isn't working very well.
If I use
<img src="<? echo 'http://www.mysite.co.uk/'.$row['imageLocation']; ?>">
the images load but it is very slow
If I use
<img src="<? echo '/home/myname/public_html/mysite.co.uk/'.$row['imageLocation']; ?>">
the images aren't displayed despite the path being correct. If I use the same path for getting the images sizes (getimagesize) it returns the correct results so I'm sure the path is correct.
The images arent shown because you echo the path to the user first, but not the file itself and then the users browser loads them asynchronously. He cannot access any parent directory from mysite.co.uk only child directories.
The PHP can load them because it runs on the server itself before it is returning anything.
What you could do is using the readfile() function from PHP in an extra PHP file like getimages.php or just use the first solution, which cannot be improved in speed except you will change the image sizes, which might be your main problem here.
If you want to directly echo image file content, use this.
<img src="data:image/jpeg;base64,<?php echo base64_encode('/home/myname/public_html/mysite.co.uk/'.$row['imageLocation']); ?>" />
Html
<input type="file" name="picture" value="" />
<img id="preview_pic" src="/images/no-image.jpg" alt="" height="100" width="100" />
I can see the "file" input box gets populated with local file path. I want to replace the img src with this new local file path to just give a preview of the image they have selected. If the file they have selected isnt an image file then keep the default no-image as is. Any ideas how to do this with Jquery. Once the form is submitted, I can process the file on server.
Thank you.
[ps - I am not sure which event to use, which makes sure that user has selected a file. for example I use onclick when user has clicked etc]
You cannot do this because of security restrictions. For most browsers, if a page fetched over http:// has a file:// url in its contents (or you construct one from the file input), the file will not be retrieved. The apparent exception is older versions of Internet Explorer (though I haven't tested this myself).
There are some plugins that use Adobe Flash to enable client-side image preview prior to upload, but you must then also make sure your server is configured correctly to handle the upload itself when it happens.
This may be just a thought/idea...
You can copy the image to be uploaded in temp folder internet "%temp%" folder where web pages data is cached and try to open on client machine for preview using javascript commands.
Here's the snippet that might help you -
x-browser file input handing
Choose an image:
<input type='file' onchange="document.images[0].src=getPath(this);" />
preview
<img src="#" alt="your image" />
Compatibility
tested in FF3.5, chrome, IE8.
IE8 needs a security settings change: internet settings, security, custom level :
[] Include local directory path when uploading files to a server
( ) Disable
(o) Enable
function getPath(input){
if(input.files && input.files[0]){
return input.files[0].getAsDataURL();
}
return input.value || "No file selected";
}
I have not tested this. Yes.This may be present in HTML 5.