How to Add Image Uploading to Your CMS

  You are currently not logged in. You can view the forums, but cannot post messages. Log In | Register

31-May-12 01:00
This is a forum topic for discussing the article "How to Add Image Uploading to Your CMS":

http://www.elated.com/articles/add-image-uploading-to-your-cms/

Learn how to modify a PHP and MySQL content management system so that you can upload an image for each article. Full CMS code download included.
31-May-12 14:05
@Thanks Matt.

You are the Number ONE. !!!!!!

Hi Volks Enjoy It.

Let me say, a Comment Sytem Would be Great too.

Thanks Matt.
03-Jun-12 10:24
I used your first CMS tutorial as an base for a CMS and I have added:

a comment section
disabling or enabling comments per article,
an upload facility for some sort of an introduction image
added a sidebar to show some recommended links, an ad and a random article that's published
changed the date column in SQL to datetime to add more exact listing of new articles

Thank you for your tutorial as it has helped me develop my PHP OOP style programming skills a lot.
03-Jun-12 10:27
Awesome tutorial Matt!

if you're going to write any more tutorials for this CMS I'd have to say a archive pagination tutorial or a comment system would be very useful and appreciated.
11-Jun-12 11:27
@hannz: Any chance you could do a small tutorial on how to implement comments, if you ever have the time?

@matt: Just wondering, any specific reason you chose to do this tutorial using the original CMS instead of the one with Categories?
15-Jun-12 04:45
@MarcusS: The main reasons were (1) to keep the code size down in the article, and (2) because some people might want to add image uploads without having categories.

--
Matt Doyle, Elated
03-Jul-12 05:00
Hi Matt,

very nice and clean tutorial about image uploading to CMS.

how do i made it so that this cms can upload multiple image?

I'm doing my own photography website which needs to display lots of photo..
13-Jul-12 03:40
@cydo: It depends what you mean exactly. Multiple images from the same form? Multiple images attached to a single article? Additional images that aren't associated with an article?

--
Matt Doyle, Elated
13-Jul-12 12:51
I'm also wondering how to attach multiple images to the same article. I've made some changes in the editArticle.php (in the form), so I can add dynamiclly multiple inputs (as many as I want), but I have some trouble to change the storeUploadedImage in Article.php . Maybe you could give me a hint?
26-Jul-12 10:12
Hi Matt can you explain how to upload multiple images? And also if possible how to use that to create a gallery page? Thanks!!
27-Jul-12 02:54
@LightningPL @eddie: If you want an arbitrary number of images per article then you'll need to create a separate articleImages table with articleId, filename, and so on, so you can associate each uploaded image with the correct article. You'll then probably want to add an imageIds array to the Article class to store the images associated with the article. Then mod storeUploadedImage() so that it stores all the uploaded images, creates their records in the articleImages table (and ids in the imageIds array), and saves the Article record. Then you'll need to modify the "view article" code to handle display of multiple images per article.

In short, it's quite a lot of work!

If there's enough demand, and many people find it useful to associate more than 1 image per article, I may write a tutorial on it at some point. If you just want to include lots of images within an article's content then you're probably better off using FTP and adding the image URLs within the content as img tags.

--
Matt Doyle, Elated
27-Jul-12 06:27
Hi Matt,

First of all (what I've forgot to mention earlier) great tutorials, they a a great source of knowleadge and inspiration.

Also maybe your idea of uploading images through ftp and attaching URLs to the articles is more resonable. What do you think about (I mean if it's rational):

creating a folder with the title of the article, where all the images for this article would be stored (if the titleis changed, so will bethe folder name too). Then reading all the files from the folder and printing them on the website?
27-Jul-12 07:56
Hi Matt I posted questions in a few different forums' topics
and I want to thank you for taking the time to answer all of them
I really appreciate, they are all very helpful, and I'm a big fan of your website and the tutorials.
Thanks again.
30-Jul-12 23:38
@matt: yes, i need t to associate more than 1 image per article. can you make the tutorial? thank you in advanced
01-Aug-12 11:07
@Matt: I would really like to thank you for all this amazing work. You're helping us a lot, many thanks!!!!
I am integrating this amazing cms on a website but:
What if i would like to add another table for some news, or some job descriptions? Should i follow the same style? Note that I will not need to have any photo for this other table.

I mean to add two different tables in database and manage them accordingly:
News: id, title, source(oprional)
Jobs: id, job title, Essential Duties, Essential Skills, Desirable Skills, ApplyTo(email)

I would really appreciate your advice in general terms before starting with the implementation.

Again, Thank a lot for this wonderfull work.
03-Aug-12 03:48
@LightningPL: Yes, that could work, if you mean reading them automatically - though of course you wouldn't have any control over exactly where each image appears in the article page. Depends what you want to do really. You could also use the article ID instead of the title for the folder name, which might be easier to work with.

@ekaja: Yes, I would probably create separate DB tables and PHP classes for those content types, if they're sufficiently different from regular articles. You can base them on the original articles table / Article class. For content that is similar to articles, I would instead store them in the articles table and use categories ( http://www.elated.com/articles/add-article-categories-to-your-cms/ ) to distinguish them.

Thanks for the kind words everyone - I really appreciate it.

--
Matt Doyle, Elated
25-Oct-12 09:08
matt, first I'd like to thank you for the great tutorials you have given to the community. I have a question relating to the image upload script. I was wondering how to limit the form to except only jpg images and if it will except only the extension jpg or to convert jpeg to jpg. Help on this would be much appreciated as I've attempted a few things with no success. It would be nice to be able to notify the admin on submit that the extension used was not an excepted file type and do a header to bring them back to the form to correct it instead of taking them to the list of articles saying your changes have been saved.
31-Oct-12 21:15
How to add a category list too?
12-Nov-12 22:02
Hi, could you PLEASE make a tutorial on how to upload multiple images to an article?

Thank you so much for your great work.
15-Nov-12 18:55
Hi Matt, very great and useful tut. I am wanting to integrate a way to load pages of the CMS data without reloading the page content. Basically I am wondering if it is possible to integrate Ajax calls to avoid reloading of index page on your CMS easily. Thanks in advance!

[Edited by jvt4 on 15-Nov-12 18:58]
21-Nov-12 20:28
@meTony: Depends how strict you want it to be. You could just compare the filename extension (the Article::storeUploadedImage() method shows how to get this) to the string ".jpg" or ".jpeg". Obviously this could be faked. Or you can use http://php.net/manual/en/function.getimagesize.php to inspect the image data itself.

@lafamosa: See http://www.elated.com/articles/add-article-categories-to-your-cms/

@jonathanzuniga: I'll see if I have time. Also see my hints earlier in this thread.

@jvt4: You mean on the front end? Certainly possible. jQuery's Ajax methods - especially load() - should do what you need. More info:

http://www.elated.com/articles/ajax-with-jquery-a-beginners-guide/

Cheers,
Matt

--
Matt Doyle, Elated
23-Nov-12 12:55
Yes I am trying to integrate front-end ajax. My steps so far are:

1.) Created a new page called "content.php" with a div "#content" called content which is supposed to initially load "homePage.php" inside of it using jQuery Ajax .load;

2.) Edited homePage.php's article-specific links to "viewArticle.php"

$('#getArticle').click( function() {
var data = { articleId=$article };
$('#content').load( "viewArticle.php", data );
} );


3.) Edited homePage.php's bottom link to "viewArchive.php"

$('#getArchive').click( function() {
var data = { ???NULL??? };
$('#content').load( "archive.php", data );
} );


Is this the right direction? It seems like it could work but seems like there's an easier way.

[Edited by jvt4 on 23-Nov-12 13:03]
17-Dec-12 15:51
@jvt4: Yes that seems like the right idea to me.

--
Matt Doyle, Elated
25-Apr-13 12:01
Matt, great job on the tutorials. I must say I have learned an enormous amount of php over the last few months due to using your CMS as a foundation.

However, I am having a bit of an issue when I move everything from my localhost to my mediatemple server. I have fixed a ton of the errors that I had but these two persist.

1) The dates bump one day back every time I add a new post. Also, when I update the post it bumps one day further back. I have changed the timezone to America/Chicago from the php website and have looked at a few of the UNIX time fixes and havent really found anything that worked yet.

2) I am getting an invalid argument error and header error when I try to delete a post. Here is the error that I get from the browser (this is for a church so Article was replaced by Sermon):

[i][b]Warning: Invalid argument supplied for foreach() in tylercookmedia.com/html/clients/agape/admin/classes/Sermon.php on line 162

Warning: Invalid argument supplied for foreach() in tylercookmedia.com/html/clients/agape/admin/classes/Sermon.php on line 167

Warning: Cannot modify header information - headers already sent by (output started at tylercookmedia.com/html/clients/agape/admin/classes/Sermon.php:162) in tylercookmedia.com/html/clients/agape/admin/add-sermon.php on line 145[/b]
[/i]

Here is the code from all of those lines and I am pretty much stuck as to what the problem is sense it works locally but not on the live server.

line 162

// Delete all fullsize images for this Sermon
foreach (glob(SERMON_IMAGE_PATH . "/" . IMG_TYPE_FULLSIZE . "/" . $this->id . ".*") as $filename) {
if ( !unlink( $filename ) ) trigger_error( "Sermon::deleteImages(): Couldn't delete image file.", E_USER_ERROR );
}


Line 167
 
// Delete all thumbnail images for this Sermon
foreach (glob( SERMON_IMAGE_PATH . "/" . IMG_TYPE_THUMB . "/" . $this->id . ".*") as $filename) {
if ( !unlink( $filename ) ) trigger_error( "Sermon::deleteImages(): Couldn't delete thumbnail file.", E_USER_ERROR );
}


Header Error on line 145 (im assuming that once the for each error is resolved this one will work itself out)


function deleteSermon() {

if ( !$sermon = Sermon::getById( (int)$_GET['sermonId'] ) ) {
header( "Location: add-sermon.php?error=sermoneNotFound" );
return;
}

$sermon->deleteImages();
$sermon->delete();
header( "Location: add-sermon.php?status=sermonDeleted" );
}


Any ideas on what could be causing this would be much appreciated.
30-Apr-13 01:54
@tylercook:

1) Make sure your PHP timezone is the same as the MySQL timezone on the server.

2) The "Cannot modify header information" error is merely a side-effect of the first error being reported.

You'll want to add some debugging to see what glob(SERMON_IMAGE_PATH . "/" . IMG_TYPE_FULLSIZE . "/" . $this->id . ".*") is actually returning. It should be an array. If it's not then you'll get that "Invalid argument supplied" error. My guess is it's returning FALSE which means there's a problem accessing the filesystem (eg permissions problem or file not found).

--
Matt Doyle, Elated
20-May-13 20:17
I used your CMS tutorial and then added the Category tutorial and everything worked great. When I went to add the images tutorial, I received error on the adding new articles page:

Warning: PDOStatement::execute(): SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens in /Applications/MAMP/htdocs/cms/classes/Article.php on line 292

Warning: PDOStatement::execute(): SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens in /Applications/MAMP/htdocs/cms/classes/Article.php on line 292

Warning: Cannot modify header information - headers already sent by (output started at /Applications/MAMP/htdocs/cms/classes/Article.php:292) in /Applications/MAMP/htdocs/cms/admin.php on line 133

I wasn't sure why this error was popping up. Any solution? They seem to work independently; however, when I use the code from the image uploaded and category, it pops up with errors.
31-May-13 18:05
Matt,
Is there any basic solution to help solve the problem I'm having with the above post.

The Category and Image upload don't seem to work together. I kept receiving errors.

Original Post:
I used your CMS tutorial and then added the Category tutorial and everything worked great. When I went to add the images tutorial, I received error on the adding new articles page:

Warning: PDOStatement::execute(): SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens in /Applications/MAMP/htdocs/cms/classes/Article.php on line 292

Warning: PDOStatement::execute(): SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens in /Applications/MAMP/htdocs/cms/classes/Article.php on line 292

Warning: Cannot modify header information - headers already sent by (output started at /Applications/MAMP/htdocs/cms/classes/Article.php:292) in /Applications/MAMP/htdocs/cms/admin.php on line 133

I wasn't sure why this error was popping up. Any solution? They seem to work independently; however, when I use the code from the image uploaded and category, it pops up with errors.
21-Jun-13 01:09
how to save title, summary Unicode format now
we can only saving content in Unicode format

--
rajesh p
15-Aug-13 15:48
thank you for these tutorials they are a good base for people to build upon im trying to figure out why this in particular isnt working, some are saying it's because of the categories here, idk, the images are being uploaded (fullsize and thumbnail) but it isnt being linked with the article, it doesnt show neither on the editing page nor on the article view page

edit: for some reason the .jpg .png .gif etc extensions arent being stored in the database, if i manually store the .jpg on the article i want it at it will work fine hmmm

edit: solved xD my mistake when overwritting stuff, forgot to include the caregoryId part on the sql statement :3 tip to whoever has any issues with this tutorial: follow the white rabbit :3

[Edited by Evan on 15-Aug-13 18:09]
12-Sep-13 02:36
Thanks for the cms images tutorial, I got the images to upload to the thumbs and full-size okay but not display, can you tell me where I went wrong? Thanks.
20-Nov-13 14:23
Hello,

I like this script, its great working with CMS in afternoon.

At the moment the images are storred as id.extesion like 1.jpg ore 1.png
Is it possible to store the images with the title, like nice_cms_job.jpg ore nive_cms_job.png ?

I like the images found by searchmachines, so the name of the image is better found by name thene by id.

Thanks,
Greetings

--
If its not fun, youre not doing it right
02-Mar-14 17:12
Good article but I get the following error after I've chosen the image to upload and tried to save the article, could you tell me where I'm going wrong? I'm a noob

Warning: move_uploaded_file(/images/articles/fullsize/6.png): failed to open stream: No such file or directory in E:\xampp\htdocs\test\cms\classes\article.php on line 104

Warning: move_uploaded_file(): Unable to move 'E:\xampp\tmp\phpD717.tmp' to '/images/articles/fullsize/6.png' in E:\xampp\htdocs\test\cms\classes\article.php on line 104

Fatal error: Article::storeUploadedImage(): Couldn't move uploaded file. in E:\xampp\htdocs\test\cms\classes\article.php on line 104

Line 104 is:

if ( !( move_uploaded_file( $tempFilename, $this->getImagePath() ) ) ) trigger_error( "Article::storeUploadedImage(): Couldn't move uploaded file.", E_USER_ERROR );
01-Apr-14 22:10
What a great tutorial, just what I was looking for purely for my own home use, in cataloguing my record collection, however I have tried to alter the homepage.php to display as a table but no matter what I do I cant get it to work properly, for some reason the image will not display, its all but there and I am sure its a very simple fix but I can no longer see the error for looking. this is the homepage.php now it works but not correctly, can anyone help at all.



<?php include "templates/include/header.php" ?>

<?php foreach ( $results['articles'] as $article ) { ?>
<?php if ( $imagePath = $article->getImagePath( IMG_TYPE_THUMB ) ) { ?>
<?php
//Table headings
echo "<table border='1' cellpadding='5' align='center'>";
echo "<tr><th>ID</th><th>Date</th><th>Image</th><th>Title</th><th>Statement</th></tr>";
echo "<tr>";
echo '<td>' . $article->id . '</td>';
echo '<td>' . date('j F', $article->publicationDate) . '</td>';
echo '<td><a href=".?action=viewArticle&amp;articleId= . $article->id ."><img class="articleImageThumb" src=" . $imagePath . " alt="Article Thumbnail" /></a></td>';
//echo '<td>' .action=viewArticle&amp;articleId=echo $article->id . '</td>';
echo '<td>' . htmlspecialchars( $article->title ) . '</td>';
echo '<td>' . htmlspecialchars( $article->summary ) . '</td>';

echo "</tr>";
echo "</table>";
}
}
?>
<p><a href="./?action=archive">HOME PAGEArticle Archive</a></p>
<?php include "templates/include/footer.php" ?>

05-Apr-14 06:30
Hello Matt! First of all thanks for the truly beautiful, clear, and practical tutorials. Everything works perfectly! I'm starting to learn php with your own examples. Now, I would simply add to the file: editArticle.php another data field. Also edit the file: classes/Article.php adding the new id of the new field created in editArticle.php. I also create a new field in mysql with the same id. The field should be a more content. If I change all these parameters... load a list of errors appear endless! How can I fix it? I tried searching the forum but have not found an answer! Thanks again for everything you have done and I hope that you will continue to do! Hello;-);-)
22-Apr-14 08:34
hi guys,first of all i wanna thank matt for this awesome tutorial, i've modified the original cms to have some amazing features but what i can't seem to get right is how to implement pagination for the archive page and the list articles page at the admin section.i've searched the entire web and i've seen many tutorials written in pdo but i can't seem to implement it into the cms please anyone who has any help should pls reply or i'll prefer matt to make another tutorial on pagination.pleaaaseeee i need this so my site can go live...pls

--
dan
21-Jun-14 10:49
Hello all,

please help me !

On a local NAS server i have no problem.
But on a hosting service (OVH),
I've a problem while trying to upload the file :

here is the message (it seems the variables can't be taken into account).

Warning: move_uploaded_file() [function.move-uploaded-file]: Filename cannot be empty in /home/xxx/www/cms/classes/Article.php on line 257

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phpTD5F91' to '' in /home/xxx/www/cms/classes/Article.php on line 257

Fatal error: Article::storeUploadedImage(): Couldn't move uploaded file. in /home/xxx/www/cms/classes/Article.php on line 257
21-Jun-14 15:16
Check the permissions to the tmp folder.

--
Chris.
So long, and thanks for all the fish.
http://webmaster-talk.eu/
29-Jun-14 15:48
Thank you chrishirst fro your answer. I can't check it as I'm on a shared hosted server and don't have access to that.

I wanted to change the default tmp folder for one I would have chosen with upload_tmp_dir but it keeps using "tmp" by default.

Which bypass I could use please ?

[Edited by LeonTheOne on 29-Jun-14 14:48]
30-Jun-14 08:26
put a php.ini file in your document root folder with the following in it:




upload_tmp_dir = your_temp_folder_path


--
Chris.
So long, and thanks for all the fish.
http://webmaster-talk.eu/
01-Jul-14 15:26
Chris thanks for your help and support.

What I tested before my first post :

I set ini_set("upload_tmp_dir" , "temp"); in config.php

1)
-> not taken into account, still the same message
-> I read somewhere that "upload_tmp_dir" is part of PHP_INI_SYSTEM which means it can only be set in php.ini or httpd.conf
2)
-> this is the point you tell me and I applied it but still the same error message
-> I read that my hoster doesn't allow php.ini file to change settings on mutualized servers so it means I can add it on the root folder but not taken into account indeed

I would definitely like to make it work on that sort of server. It's possible to run strong known CMS with same functiunalities on mutualized server so I think it's possible to do it with Matt's incredible CMS.

P.S. I there a beautiful view from the tower today ?
15-Feb-15 14:48
Congratulations! Wonderful work!
I saw that you already answered many times about the possibility of creating a multiupload to associate multiple images (2-3-4-5 etc ...) to an article. Saying it was a long process ... but if I wanted to upload three images for each item? It would also be a long and difficult, or maybe there's a simpler way to do it?
Thanks in advance for your reply and keep it up! The web improves mainly thanks to you!
17-Feb-15 03:57
I guess, you can get some info on http://www.webbuildersguide.com website. There are some lessons and reviews on different CMSs. I am learning web design from there now. I guess, those tutorials are nice
17-Feb-15 06:34
Thanks for the advice! But I love this "simple" cms!
I edited all styles using the bootstrap fremwork.
Added 3 fields to insert more data.
Added a search bar.
Create an initial password to be able to see the blog ...

What I miss is just give the possibility to add 3 images for every article ...
Any ideas?

Thanks in advance to all community!

Regards
17-Feb-15 16:02
Hi Emanuele, I saw your reply to the topic, would you send me the address of your cms when you're done so I can see it? I love working with bootstrap framework and read on the reply what you have done with it, thanks.
18-Mar-15 01:11
This is great news widget. Please can you help me. How do get the articles to display three in a row? Also How can you specify which article displays on which page?

[Edited by AllyD on 19-Mar-15 07:21]
08-Apr-15 02:59
Good afternoon! There is a problem downloading files larger than 2MB, and I can not understand what the problem is. Help me please. (CMS on the localhost)
08-Apr-15 09:40
Check the maximum upload size in php.ini

--
Chris.
So long, and thanks for all the fish.
http://webmaster-talk.eu/
13-Apr-15 08:45
Thank, chrishirst!
02-Sep-15 20:52
I insert a new columns in the article's table in the database, for language proposals... Called publicationDate_fin, title_eng, content_eng, summary_eng. So, the insert function is now like this:



public function insert() {

// Does the Article object already have an ID?
if ( !is_null( $this->id ) ) trigger_error ( "Article::insert(): Attempt to insert an Article object that already has its ID property set (to $this->id).", E_USER_ERROR );

// Insert the Article
$conn = new PDO( DB_DSN, DB_USERNAME, DB_PASSWORD );
$sql = "INSERT INTO articles ( publicationDate, publicationDate_fin, title, title_eng, summary, summary_eng, content, content_eng, imageExtension ) VALUES ( FROM_UNIXTIME(:publicationDate), FROM_UNIXTIME(:publicationDate_fin), :title, :title_eng, :summary, :summary_eng, :content, :content_eng, :imageExtension )";
$st = $conn->prepare ( $sql );
$st->bindValue( ":publicationDate", $this->publicationDate, PDO::PARAM_INT );
$st->bindValue( ":publicationDate_fin", $this->publicationDate_fin, PDO::PARAM_INT );
$st->bindValue( ":title", $this->title, PDO::PARAM_STR );
$st->bindValue( ":title_eng", $this->title_eng, PDO::PARAM_STR );
$st->bindValue( ":summary", $this->summary, PDO::PARAM_STR );
$st->bindValue( ":summary_eng", $this->summary_eng, PDO::PARAM_STR );
$st->bindValue( ":content", $this->content, PDO::PARAM_STR );
$st->bindValue( ":content_eng", $this->content_eng, PDO::PARAM_STR );
$st->bindValue( ":imageExtension", $this->imageExtension, PDO::PARAM_STR );
$st->execute();
$this->id = $conn->lastInsertId();
$conn = null;
}


But... When i'm going to upload a new event with all the content and the image, it shows me forever this error:



Warning: move_uploaded_file(): Filename cannot be empty in /home3/healthot/public_html/o-e/es/eventos/classes/Article.php on line 121

Warning: move_uploaded_file(): Unable to move '/tmp/phpvi3TPX' to '' in /home3/healthot/public_html/o-e/es/eventos/classes/Article.php on line 121

Fatal error: Article::storeUploadedImage(): Couldn't move uploaded file. in /home3/healthot/public_html/o-e/es/eventos/classes/Article.php on line 122


It's only happen's in the insert function, because if i want to edit an existent article, it's working fine. So the update function is this:



public function update() {

// Does the Article object have an ID?
if ( is_null( $this->id ) ) trigger_error ( "Article::update(): Attempt to update an Article object that does not have its ID property set.", E_USER_ERROR );

// Update the Article
$conn = new PDO( DB_DSN, DB_USERNAME, DB_PASSWORD );
$sql = "UPDATE articles SET publicationDate=FROM_UNIXTIME(:publicationDate), publicationDate_fin=FROM_UNIXTIME(:publicationDate_fin), title=:title, title_eng=:title_eng, summary=:summary, summary_eng=:summary_eng, content=:content, content_eng=:content_eng, imageExtension=:imageExtension WHERE id = :id";
$st = $conn->prepare ( $sql );
$st->bindValue( ":publicationDate", $this->publicationDate, PDO::PARAM_INT );
$st->bindValue( ":publicationDate_fin", $this->publicationDate_fin, PDO::PARAM_INT );
$st->bindValue( ":title", $this->title, PDO::PARAM_STR );
$st->bindValue( ":title_eng", $this->title_eng, PDO::PARAM_STR );
$st->bindValue( ":summary", $this->summary, PDO::PARAM_STR );
$st->bindValue( ":summary_eng", $this->summary_eng, PDO::PARAM_STR );
$st->bindValue( ":content", $this->content, PDO::PARAM_STR );
$st->bindValue( ":content_eng", $this->content_eng, PDO::PARAM_STR );
$st->bindValue( ":imageExtension", $this->imageExtension, PDO::PARAM_STR );
$st->bindValue( ":id", $this->id, PDO::PARAM_INT );
$st->execute();
$conn = null;
}


If I add the original insert function, it's published fine, but i want to use this function because I added new rows to the articles table (publicationDate_fin, title_eng, summary_eng and content_eng).

I was trying to fix this about three days but I can't... What happen?

Thanks a lot!!!



(The admin .php editarticle is changed to get the new forms for each new row in the table, it's all correct).
03-Sep-15 07:22
This:

"Warning: move_uploaded_file(): Filename cannot be empty"


Says you haven't selected a file to upload.

--
Chris.
So long, and thanks for all the fish.
http://webmaster-talk.eu/
03-Sep-15 09:04
Hi Chris!!

Thanks for the reply.

But it's not correct, because I choosed an image to upload, so I don't know why this error occurs...

If i do a var_dump in $tempFilename it shows: string(14) "/tmp/phpGuXkGs"

If i do a var_dump in $this->getImagePath() it shows: bool(false)

If i do a var_dump in $this->imageExtension it shows: string(4) ".jpg"

If you want I can pass the .zip code to mail and the admin address to check it.

Thanks so much.

[Edited by Dreagnout on 03-Sep-15 08:25]
14-Nov-15 16:03
Any idea how to preserve transparancy when a png (maybe even GIF) with transparant background is uploaded? Or just turning it white instead of black would be an improvement too.
I tried a few Stack Overflow solutions but can't seem to get it fixed. Thanks in advance.

EDIT: fixed, edit the following code in the storeUploadedImage-function (see the classes-folder), I've copied the first and last line so you can see where it should go.


$thumbResource = imagecreatetruecolor(LINK_THUMB_WIDTH, $thumbHeight);

switch ($imageType) {
case IMAGETYPE_PNG:
// integer representation of the color black (rgb: 0,0,0)
$background = imagecolorallocate($thumbResource, 0, 0, 0);
// removing the black from the placeholder
imagecolortransparent($thumbResource, $background);

// turning off alpha blending (to ensure alpha channel information
// is preserved, rather than removed (blending with the rest of the
// image in the form of black))
imagealphablending($thumbResource, false);

// turning on alpha channel information saving (to ensure the full range
// of transparency is preserved)
imagesavealpha($thumbResource, true);

break;
case IMAGETYPE_GIF:
// integer representation of the color black (rgb: 0,0,0)
$background = imagecolorallocate($thumbResource, 0, 0, 0);
// removing the black from the placeholder
imagecolortransparent($thumbResource, $background);

break;
}

imagecopyresampled($thumbResource, $imageResource, 0, 0, 0, 0, LINK_THUMB_WIDTH, $thumbHeight, $imageWidth, $imageHeight);


[Edited by tjorim on 14-Nov-15 16:43]
16-Jan-16 06:23
Hey this is rily great,
I am new to programing language, I am wondering how i can pick one article and its image displayed separately in my div tag. such that it may not be a rondom pick on my home page,

something like



$result = mysql_query("SELECT * FROM articles WHERE id =1",

and how do i add the image path to crespond my article. Thank you.
02-Mar-16 21:22
In case I want users to login to my system to comment and i want them to be able to upload their profile picture, would you recommend saving the profile picture as part of, let's say, a USERS table? Also would you recommend saving the admin login as part of the USERS table, with a is_admin field to indicate if it's an admin user, instead of keeping it as part of config.php? I'd like to know which is more secure way to handle these.

[Edited by bentotdecruz on 02-Mar-16 21:23]
03-Mar-16 07:22
"Also would you recommend saving the admin login as part of the USERS table, "

Not really, You STILL have to have a username and password in config.php so that the "admin" login details CAN be retrieved from the database.

Provided you have changed the password to something that is difficult to 'break', and here longer, (ten characters minimum) passwords are better than using a shorter 'complex' password of letters and numbers. Having the password in a text file is reasonably secure, as you can block config.php from being requested externally using .htaccess directives and even if someone were to access it, the resulting page would be blank, as PHP only serves content to the user agent that is echo()ed or print()ed to the output stream for the browser to display. So any thing between <?php .... .... and ?> is 'invisible' to the outside world.

--
Chris.
So long, and thanks for all the fish.
http://webmaster-talk.eu/
13-Apr-16 10:26
Hi,
I have this working perfectly locally but not when on a server. I'm getting "Call to undefined function imagecreatefromjpeg" . I am using php 5.1.6 on the server and am stuck with that. Is there a way I can rewrite the method to make it work with the old version of PHP I have to use?
Thanks
13-Apr-16 11:21
Probably nothing to do with the version of PHP as "imagecreatefromjpeg" is actually part of the "GD" (http://php.net/manual/en/book.image.php) library included with PHP but which is often disabled in "shared" hosting configurations.
Check it is on by putting

<?php phpinfo() ?>

in a php document and request that URL in a browser, if the GD section does not appear you will probably need to ask your hosting provider to enable it, or check in whatever control panel you have to enable or disable there.

--
Chris.
So long, and thanks for all the fish.
http://webmaster-talk.eu/
13-Apr-16 16:19
Thanks got it working...
Now about the multiple image issue.
I was wondering if I could just upload multiple images within the editArticle.php page. They don't have to be associated with the article. I just need them to go to different directories. Then I can just reference them within the wysiwyg. I can't ftp.
Thanks
16-Apr-16 11:50
Given that the edit article page is for associating the image with an article, you can't, well no without a fair bit of reinventing anyway.

The simplest way would be to take a basic PHP upload form and script such as http://www.w3schools.com/php/php_file_upload.asp and make that the default document ( probably index.php) for a subfolder of the website and by including the config.php and login() check function you could integrate it as if it was part of the site.

Just set the redirect header location: of login() to your upload URL instead of admin.php

Then to upload an image you just request

yoursite.tld/uploadfolder/

In a browser and the upload form will be presented.

Probably best not to call it "upload" anything though and of course set the "$target_dir" value to a different location, so if the Internet scrotes find it they can't do too much damage with uploading 'fake' images that actually run scripts.

And never link to that URL so it will not be exposed to any bots that are scraping the site looking for upload forms.

--
Chris.
So long, and thanks for all the fish.
http://webmaster-talk.eu/
18-Apr-16 09:47
Thanks Chris,
I did do something very similar. I had the image upload as a popup window so the content editor could copy/paste image paths into the wysiwyg editor after they were uploaded. Also you can't nest forms so that is another reason for the popup. They can upload as many as they want that way.

I think the last issue I have would be publishing the articles. What I mean by that is creating static html files from the output of the articles. I appreciate all the feedback you have given.
10-May-16 04:51
Please add pagination to archive page. It is major demand of every one over here, Thanks. If any body have added, please post the code here or mail me.

--
jatinbedi
20-Nov-16 18:04
I will start by saying a very Big thank by sharing this application.this really help me in my PHP learning journey.
Please I have problem with this image upload.I have been following the tutorial,and everything was working fine until I get to.


( ! ) Warning: move_uploaded_file(images/articles/fullSize/9.jpg): failed to open stream: No such file or directory in C:\wamp\www\NewD9\classes\Article.php on line 105
Call Stack
# Time Memory Function Location
1 0.0013 163128 {main}( ) ..\admin.php:0
2 0.0058 247456 editArticle( ) ..\admin.php:24
3 0.0999 248896 Article->storeUploadedImage( ) ..\admin.php:118
4 0.1003 249184 move_uploaded_file ( ) ..\Article.php:105

( ! ) Warning: move_uploaded_file(): Unable to move 'C:\wamp\tmp\php242D.tmp' to 'images/articles/fullSize/9.jpg' in C:\wamp\www\NewD9\classes\Article.php on line 105
Call Stack
# Time Memory Function Location
1 0.0013 163128 {main}( ) ..\admin.php:0
2 0.0058 247456 editArticle( ) ..\admin.php:24
3 0.0999 248896 Article->storeUploadedImage( ) ..\admin.php:118
4 0.1003 249184 move_uploaded_file ( ) ..\Article.php:105

( ! ) Fatal error: Article::storeUploadedImage(): Couldn't move uploaded file. in C:\wamp\www\NewD9\classes\Article.php on line 105
Call Stack
# Time Memory Function Location
1 0.0013 163128 {main}( ) ..\admin.php:0
2 0.0058 247456 editArticle( ) ..\admin.php:24
3 0.0999 248896 Article->storeUploadedImage( ) ..\admin.php:118
4 0.2960 249728 trigger_error ( ) ..\Article.php:105
22-Nov-16 15:31
"move_uploaded_file(images/articles/fullSize/9.jpg)"

File or folder does not exist or permissions are incorrect.

--
Chris.
So long, and thanks for all the fish.
http://webmaster-talk.eu/
05-Apr-17 15:59
Hi,
I have spent hour looking for a script that will do the things this will - namely upload an image with the news article.
This would work for me but I have some concerns of how secure it will be on a shared web hosting.Is there anyway we can make it more secure.

Kind Regards
Chris
05-Apr-17 16:40
It will be just as secure as the permissions are on the server folder structure.

--
Chris.
So long, and thanks for all the fish.
http://webmaster-talk.eu/
05-Apr-17 17:05
I have concerns about folders being 777 and the password in the config file..
06-Apr-17 07:37
Folders should definitely not be that open, at worst only the image folder may need "world write" permissions to allow for uploading.

Anyone trying to access the config.php file from 'outside' should not see the information as it is only setting values and does not write any data to the output stream with echo(), print() etc. Plus you can block the file from access over HTTP using .htaccess directives.

If the image upload folder does require "world write" permissions you should use a folder .htaccess file to block executable scripts and common exploits such as 'double extension' files.

A template that I use is at http://chrishirst.co.uk/download/htaccess.txt

Change the necessary details and save the file as .htaccess in the images folder.

--
Chris.
So long, and thanks for all the fish.
http://webmaster-talk.eu/
17-Apr-17 14:40
Cheers for the reply Chris,

Been having a play around but keep running into the same problem..

Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000] [1044] Access denied for user 'cmsus'@'localhost' to database 'CMS'' in /home/test/public_html/cms/classes/Article.php:216 Stack trace: #0 /home/test/public_html/cms/classes/Article.php(216): PDO->__construct('mysql:host=loca...', 'cmsus', '0Etptii8msn6') #1 /home/test/public_html/cms/index.php(40): Article::getList(5) #2 /home/test/public_html/cms/index.php(14): homepage() #3 {main} thrown in /home/test/public_html/cms/classes/Article.php on line 216

Password is ok just can't put my finger on whats wrong...
18-Apr-17 08:00
This;
"Access denied for user 'cmsus'@'localhost' to database 'CMS''

Suggests that the MySQL user 'cmsus'@'localhost' does not have "SELECT" privilege granted on database 'CMS''.

Login to mysql in a console session as the 'root' user and use;


show grants for 'cmsus'@'%';


To display what privileges are granted to that user.

OR

if the cms is NOT public facing on the Internet you can simply grant ALL privileges to that user,


GRANT ALL PRIVILEGES ON CMS.* TO 'cmsus'@'localhost';


followed by


FLUSH PRIVILEGES;

to reload the privileges

if the cms is public facing, you should only grant the minimum necessary privileges to that user. with;


GRANT [type of permission] ON [database name].[table name] TO ‘[username]’@'localhost’;


and the [type of permission] can be a comma separated list of these;


CREATE - allows them to create new tables or databases

DROP - allows them to them to delete tables or databases

DELETE - allows them to delete rows from tables

INSERT - allows them to insert rows into tables

SELECT - allows them to use the Select command to read through databases

UPDATE - allow them to update table rows

GRANT OPTION - allows them to grant or remove other users' privileges


The GRANT OPTION privilege should be used with care if anyone else has access to the machine that the CMS is running on regardless of external access, so do not grant this to ANY user for all databases and tables unless you are granting permissions for an secondary 'root' user.

--
Chris.
So long, and thanks for all the fish.
http://webmaster-talk.eu/
18-Apr-17 15:24
Have it working now, it did not like the auto generated password.

My next question is.

I need to be able to insert paragraph mark-up tags when enter on the key board is hit, in the new article "Article Content" form. As this form I'm typing in now does.

Chris
19-Apr-17 13:28
I did not make myself very clear in the above post, I think sleep was needed.

When the user enters new lines, the new lines don't appear when they are outputted. Is there any way to make the line breaks stay. How do preserve the line breaks as I'm getting just one long text no formatting. I have tried <pre></pre>but this just mess's with the page style .

Chris

[Edited by Big Chris on 19-Apr-17 12:29]
20-Apr-17 08:02
You need to convert 'newline' characters (ASCII 10) and 'carriage return' characters ASCII 13 to HTML line breaks (BR) as the document is being processed server side when it is requested.

http://php.net/manual/en/function.nl2br.php

[Edited by chrishirst on 20-Apr-17 07:03]

--
Chris.
So long, and thanks for all the fish.
http://webmaster-talk.eu/
20-Apr-17 13:57
I have been reading up on this, https://goo.gl/HRryJG , but it's all above my skill level. I would not know where to start...Which is a shame as everything else about this CMS works for me...

Chris
21-Apr-17 04:50
"but it's all above my skill level."


That's actually the purpose of the tutorial, it is here for you to improve your coding skills while creating something useful.

The intention of publishing it was not for anyone to use 'as is' but as a learning tool.

--
Chris.
So long, and thanks for all the fish.
http://webmaster-talk.eu/
23-Apr-17 05:40
That's fine and I do understand that.

But, when the example is trowing up an error and ones understanding of php is not great, a little help is needed.

<?php
string nl2br ( string $string [, bool $is_xhtml = true ] )
?>


Gives a (T_STRING) error ....
23-Apr-17 08:51
so what does YOUR code for calling that function 'look' like, because showing the example from the PHP manual is of no help in diagnosing where you may have gone awry.

However; a T_STRING error generally means that the PHP interpreter encountered a string of characters where one not expected.

This could be caused by some text that is not wrapped in quote marks ( " or ') or a variable name that is missing a '$' sign,

eg. variable instead of $variable.


So, just in case you have done what I think you may have done,

The call to nl2br() at it's simplest should be.

echo(nl2br($var_containing_text_from_database));


--
Chris.
So long, and thanks for all the fish.
http://webmaster-talk.eu/
23-Apr-17 09:08
Think I just call it a day and look for something of the shelve. I'm just going around in circles and not getting very far...

Thanks for all the help..
23-Apr-17 09:32

<?php echo $results(nl2br($var_article) ['article']->content );?>

 
New posts
Old posts

Follow Elated