Uploaded images do not appear in web - php

I have been working on a small product based site. This site has various products and descriptions along with images in it. I am using tinymce editor to upload the description and images.
But the problem is, when I copy-paste the image in the editor, it shows fine in localserver but in web it shows a sign like this \"\" and the url associated with the image is like: http://abc.com.au/products/\"abc.com.au/admin/data/test.jpg\".
Any suggestions?

Assuming you are saving the content from the editor window to a database, you need to use the stripslashes function on the string you pass from the editor to the database. That way, the content won't be altered. The slashes are added by default since characters like double quotes need to be escaped in order for the code to be parsed, as well as displayed, correctly.

Related

CKEditor images not working

I'm having some trouble with CKEditor.
I have created a blog for my website and a back end section to write new posts and approve comments etc. It's all working fine and I use CKEditor to write and edit posts.
When writing a text only post its fine, it gets stored in the database and subsequently appears on the website as it should. But If I write a post with an image in it it doesnt get stored in the database. All text and images disappear.
The title of the post goes into the database as this is just using a normal text box. But everything in the CKEditor disappears if I put an image in there.
Here are some screen shots:
I press the image button and enter in the explicit URL of the image stored on my server. (http://www.mydomain.com/images/image.jpg)
When I press ok the image is visible in CKEditor with the text above it.
When I submit the post and then return to it to view or edit it, the CKEditor is empty and only the Title is there. Checking the database I can see the title is entered but the body isnt.
If I dont enter an image everything works fine title and body go into the database and the blog post appears on the site.
Does anyone have any idea whats wrong here?
I actually discovered the answer myself
The image tags created in the CKEditor would be something like
<img src="images/picture.jpg">
and my SQL query would be something like
$query = "INSERT INTO Table (blog_body, blog_title) VALUES ('".$blogBody."','".$blogTitle."')";
or something along those lines.
To solve it I just swapped the quotation marks around. Placing the query in single quotes and swapping the quotes about the variables around.
This fixed my problem.
Just thought if someone else is having this trouble this may help

How do I edit the html when using a PHP based CMS?

I am not experienced outside of HTML and CSS.
I have a site on a less well known CMS called Ushahidi. Editing CSS is fine but right now I need to change an img selection. Currently, an image on a page has the code:
<a class="photothumb" rel="lightbox-group1" href="http://trashswag.com/media/uploads/35_1_1347312096.jpg"><img src="http://trashswag.com/media/uploads/35_1_1347312096_t.jpg"></a>
I need to remove the ability of the site to use the second image (note there is a slight difference "_t.jpg" is appended to the second src.
How would I alter the site so as to select the first image only i.e. remove the "_t" string?
The version of the image with the _t in the name is probably a thumbnail of the first image. What you have there is a small image, that when clicked takes you to a larger image. If you want to display the full-sized image and get rid of the link, just use
<img src="http://trashswag.com/media/uploads/35_1_1347312096.jpg">

CKEditor in php website

I am going to use CKEditor to format the text while editing the content of my website. The content is saved into MySQL database, so if I use CKEditor, will the text be saved with its formats (size, color, etc) and displayed with that format in client side?
Yes and no. Not really.
Some information will be saved, yes, but some other will require the CSS of the editor page and the display page to match. They usually do, but not necessarily.
CKeditor offers several ways of customizing the HTML that's being generated. Your best option would be to use CSS classes for SPAN and DIVs, and all other tags you allow in the editor; then, define those in a separated .css file that would be imported by your CKeditor edit page as well as the site at large. This will give you as much WYSIWYG as you're going to get.
(I'll try and whip up an example later when I get access to a CKeditor on my servers; but you can also looks at CKeditor' documentation).
Yes CK editor will save the way you specify. On CK editor you have a source button if you click on it you will get the html source.

Need some help in downloading pics from a website

I am looking for some help in downloading pics from a website. Here is the problem detail.
URL is basvandenbroek dot com,
suppose when we visit the following page http://www.basvandenbroek.com/nl/product/27341/704/snaarinstrumenten/boston/snarenset_elektrisch.html
we have a thumbnail pic here which when click bring its larger version. I would like to capture the larger image using a php script and download it onto my pc.
Problem is when we inspect the HTML we see the following code for images
../../../../../../../jpg/27000/27341.jpg
../../../../../../../jpg/cache/27000/220_220_27341.jpg
Based on the above code i assume that if i append website address at the start of the
jpg/27000/27341.jpg I could access the pic but its not working it that.
I believe URL is hidden or I might not understanding things properly. I am new to PHP and Scripting and I would like somebody to help me through it situation.
Thank you
For the website you mentioned, if the thumbnail is
http://www.basvandenbroek.com/jpg/cache/27000/220_220_27341.jpg
then the
http://www.basvandenbroek.com/jpg/27000/27341.jpg
So the thumbnail is basically the dimensions (220 x 220) added as a prefix to the original in a different folder. Also, there is nothing like hidden URL. Any link that is valid on a web-page is sure to appear in the source of the html. In chrome and firefox, atleat, you can find this link by right-clicking the link and copying the link address.
In your case you can find the thumbnail's url by right-clicking the thumbnail and the original's url by right-clicking it.
However, if you want to do this automatically using PHP, you will have to write code that can parse the html for the page to determine the urls.
In your example, here would be the larger image:
http://www.basvandenbroek.com/jpg/27000/27341.jpg
The smaller image is at:
http://www.basvandenbroek.com/jpg/cache/27000/220_220_27341.jpg
This means you would need to scrape out the first two underscored parts of the name (220_220) using string manipulation. You would also want to string replace "cache/" with an empty string.
relative urls are relative to the url of the containing document. so if the document you're scraping is located at http://example.com/foo/bar/baz/doc.html, and the image is referenced as
../../omg/wtf/lol/cat.jpeg, its full url is http://example.com/foo/bar/baz/../../omg/wtf/lol/cat.jpeg, or http://example.com/foo/omg/wtf/lol/cat.jpeg.
btw, this has nothing to do with PHP or scripting in general, and is instead firmly a HTTP thing. and there are no "hidden" URLs in HTTP, that would be a contradiction.
edit: your comment makes it look like the problem is with the Referer header or session id sent (or not) in your request.

php how to keep track (in database) of image tag filenames included in html ouput from ckeditor wysiwyg editor

I have changed the title to this post as I think I have not been clear with my question...
This is my first post, so please be gentle with me!
I am building a content management system for a small static site which I built for a client some years ago.
The client is eager within some content areas of the site to be able to enter formatted text and images freely - in blog-esque fashion. I've chosen ckeditor and ckfinder for these tasks.
For all other parts of the site I've no problem envisaging how this data would be uploaded/entered and stored in a database and served to each instance of template etc. My difficulty is in conceiving how I would - in PHP - extract the image filenames from the wysiwyg field content when posting data.
Would I use regex() on the $_POST['wysiwygText'] and search the html outputed by the wysiwyg editor for any .jpg/.png/.gif etc - if so what function/search argument would I use?
I'm only trying to do this as the rest of the site's image names would be stored in a db where the domain rules are more ridig eg, every menu will have either 1,2 or 2 set sized images in it's header - and text is always formated the same way...- theoretically is is good practice to store a record of images used on each page for a site? I just thought it would easier in time as client adds and takes out images to have images automatically removed when not used etc.
However I can forsee that if image names used within the wysiwyg area it might be really difficult to track many to many relationships of images used on different pages as it would be an unreasonalbe task to add this logic to ckeditor's output. Or should I just be firmer with my client and not have wysiwyg editor but simple form fields to input images within a text field - an example of some code to do that would be excellent if the wysiwyg option is deemed to unmageable.
Many thanks for any contributions/help/suggestions
You can access all of the information needed with the $_FILES Global array that is automatically created for you when an image is uploaded.
http://php.net/manual/en/reserved.variables.files.php
Example usage. Note: this has no error checking such as max file size, file type etc etc, It's only an exmaple to get you on the correct path.
if ($_FILES)
{
$uploadDir = 'images/';
$filename = $uploadDir . $_FILES['filename']['name'];
move_uploaded_file($_FILES['filename']['tmp_name'], $filename);
}
else echo "No image uploaded"

Categories