Recent Topics

[Plugin] Quick Upload

Started by on May 18, 2008 – Contents updated: Jul 22, 2013

May 18, 2008 11:52    

[Plugin] Quick Upload

Read in Russian
http://b2evo.sonorth.com/show.php/quick-upload

Works in b2evolution 2, 3 and 4

Do you have many files/images in your media folder?
When you hit the "files" button it takes a long time to load as it loads all the files/images in the folder. What if you have a few hundreds of files... >:XX :no:
Install this plugin and forget about the file manager.

Download v1.0
http://www.sonorth.com/travel/download/LEP4Y8S18F

By default it uploads files in blog's media folder (if you create or edit a post in Blog B all files get uploaded to /media/blogs/b or whatever is set as default media dir for this blog).
You can also enable directories tree in plugin settings and choose a destination directory before uploading files.

Each post may have its own directory for uploaded files (created automatically). No more mess in media folder and no more "the file already exists" errors.

TODO:

- Setting to change inserted image HTML code

[Plugin] Quick Upload
[Plugin] Quick Upload

May 18, 2008 16:54

Sounds like a nice plugin+hack! It would be really super cool if it could be done without a hack, but I know that means lots of stuff won't ever happen without it.

Cool though. I will probably be adding this one to a group blog I run. Thanks!

May 18, 2008 20:48

Thanks, I will try to copy some functions from upload.ctrl.php into plugin file and get rid of core modifications.

May 19, 2008 00:55

I moved everything to external file and there are no core hacks required now, but here is another problem.

I don't know why, but now param( 'var', 'string' ) function doesn't define a $var variable. What I mean...

param( 'var', 'string', '56' );
echo $var;

This returns Notice: Undefined variable: var message.

May 19, 2008 06:46

Plugin updated:
- no file edit required, install it and use ;)
- fixed many annoying bugs

May 19, 2008 07:01

OK, I uploaded the whole folder ( locales included )
Until I selected to specify a directory I got big RED error messages all over the upload window and no upload to the default media folder.

It sure is convenient and thanks

May 19, 2008 07:05

Well I didn't test it with *non-default* media dir path yet.
Is it /media/blogs/qwerty in your case or is it something unique?

May 19, 2008 07:35

Hi sam2kb, it's simply /media

May 19, 2008 07:47

Hi John, can you post that red message here please.

May 19, 2008 09:54

Yes, tell me about it :)
I'm happy with it as it is with directory tick option.

May 26, 2008 10:20

Stop fretting ;)

The upload is protected by login

PHP

/**
 * @global boolean Is this an admin page? Use {@link is_admin_page()} to query it, because it may change.
 */
$is_admin_page true;
 
 
$login_required true;

¥

May 26, 2008 16:19

And even if you are logged in and have permissions to access backoffice you must also have permssions to upload files.
No worries about it ;)

Jun 23, 2008 03:32

Sam you are the best! I think this was the plug in I was using before I upgraded that let me upload right from the post form and I was missing that option!

Jul 27, 2008 13:27

Plugin updated.
Added "Link this file" feature for b2evo-2.4/3.x

Jul 27, 2008 22:26

1 tiny hick-up : the window stays in the back of your current browser. Have you fixed that allready since I last updated this plugin ?

Jul 27, 2008 22:36

the window stays in the back of your current browser

What does it mean? The pop-up window can't appears in the back of the main window when you click "Quick upload". And it's small enough to move it to the side if you want so.

Maybe we are talking about different things

Jul 27, 2008 22:41

What I meant to say :
You click on 'quick upload'... and it does what it is supposed to do. You click on 'add this code...' and voila : it does what you expect it to do.
At that point the quick upload window goes under your current window, the window were you actually are writing your post.
If you write another post after that, and you click again on 'quick upload' the window does not pop in front... it stays in the back... and for that is out of your reach...
Then I need to minimize my front window, close the quick upload window, maximize my actual post again, and click again on 'quick upload'

Jul 27, 2008 22:48

You are right. I'll check if there is any javascript function to bring the window to the front. I'm not a javascript fan ;)

Jul 27, 2008 22:52

if it can help : the 'normal' upload is working correctly
except that it shows a zillion thumbnails before you upload ;)

Jul 27, 2008 23:17

Done, zip updated. Thanks Topanga, I like your ideas :p

Nov 05, 2008 07:10

I'm trying to mess with this plugin a bit. Can someone tell me the best way to get a file extension for a file being uploaded? I just want everything after the "." I can do it in straight PHP, but the b2evo variables are so confusing to me. Any help is appreciated.

Nov 05, 2008 07:35

Open upload_window.php and change the following on line 488 to get the $file_ext variable.

PHP

// Store File object into DB:
$newFile->dbsave();
 
$file_ext substr$newFile->dget('name'), strrpos($newFile->dget('name'), '.') + );

Good luck

Nov 05, 2008 17:50

Thank you so much. That did the trick. Let me give you a bit more insight into what I'm doing. I'm trying to add the functionality for the images to be resized when their uploaded.

As you mentioned, I'm putting my code after line 488, but I'm thinking it needs to be before that. Here's my code. I am learning PHP and B2Evo at the same time and things are slow-going. I appreciate the help.

PHP

// Store File object into DB:
$newFile->dbsave();
        
//MY STUFF
$filename substr$newFile->dget('name'), strrpos($newFile->dget('name'), 0) ); 
$ext substr$newFile->dget('name'), strrpos($newFile->dget('name'), '.') + ); 
        
if ($ext == "jpg" or $ext == "gif" or $ext == "png") {
    if ($ext == "jpg") { $src imagecreatefromjpeg($filename); }
    else if ($ext == "gif") { $src imagecreatefromgif($filename); }
    else if ($ext == "png") { $src imagecreatefrompng($filename); }
    list($width,$height)=getimagesize($filename);
    $newwidth=600;
    $newheight=($height/$width)*600;
    $tmp=imagecreatetruecolor($newwidth,$newheight);
 
imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height);
 
            
    if ($ext == "jpg") { imagejpeg($tmp,$filename,100); }
    else if ($ext == "gif") { imagegif($tmp,$filename,100); }
    else if ($ext == "png") { imagepng($tmp,$filename,100); }
            
    imagedestroy($src);
    imagedestroy($tmp); 
}

Lay it on me! What have I done horribly wrong :?:
Here are the errors I get when I go to upload:

Warning: imagecreatefromjpeg(test.jpg) [function.imagecreatefromjpeg]: failed to open stream: No such file or directory in /*full path*/upload_window.php on line 497

Warning: getimagesize(test.jpg) [function.getimagesize]: failed to open stream: No such file or directory in /*full path*/upload_window.php on line 500

Warning: Division by zero in /*full path*/upload_window.php on line 502

Warning: imagecreatetruecolor() [function.imagecreatetruecolor]: Invalid image dimensions in /*full path*/upload_window.php on line 503

Warning: imagecopyresampled(): supplied argument is not a valid Image resource in /*full path*/upload_window.php on line 504

Warning: imagejpeg(): supplied argument is not a valid Image resource in /*full path*/upload_window.php on line 507

Warning: imagedestroy(): supplied argument is not a valid Image resource in /*full path*/upload_window.php on line 511

Warning: imagedestroy(): supplied argument is not a valid Image resource in /*full path*/upload_window.php on line 512

Warning: Cannot modify header information - headers already sent by (output started at /*full path*/upload_window.php:497) in /*full path*/upload_window.php on line 619

(the *full path* is replaced for this forum)

Nov 05, 2008 18:39

OK. I'm very close now! The images are being resized and uploaded successfully, but still getting one error. Here's my code now:

PHP

/*line 489:*/ 
$newFile->dbsave();
        
$ext substr$newFile->dget('name'), strrpos($newFile->dget('name'), '.') + ); //GETS THE EXTENSION
$fullpath $newFile->get_full_path();
    if ($ext == "jpg" or $ext == "gif" or $ext == "png") {
        /*496*/if ($ext == "jpg") { $src imagecreatefromjpeg($fullpath);  }
        else if ($ext == "gif") { $src imagecreatefromgif($fullpath); }
        else if ($ext == "png") { $src imagecreatefrompng($fullpath); }
        list($width,$height)=getimagesize($fullpath);
        $newwidth=600;
        $newheight=($height/$width)*600;
        $tmp=imagecreatetruecolor($newwidth,$newheight);
        imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height);
 
        if ($ext == "jpg") { imagejpeg($tmp,$fullpath,100); }
        else if ($ext == "gif") { imagegif($tmp,$fullpath,100); }
        else if ($ext == "png") { imagepng($tmp,$fullpath,100); }
            
        imagedestroy($src);
        imagedestroy($tmp); 
        }

I'm still getting this error (warning, really):

Warning: Cannot modify header information - headers already sent by (output started at /*full path*/upload_window.php:496) in /*full path*/upload_window.php on line 620

Line 620 is the <!DOCTYPE> declaration, FYI.

Thanks again for any help.

Nov 05, 2008 18:42

Headers already sent is almost always caused by whitespace ( space / tab / new line ) before the opening <?php or after the closing ?>

Good luck

Nov 05, 2008 18:50

Thank you, thank you. It's working perfectly now. Here's the final code starting after line 488 of the original upload_window.php file for anyone interested:

PHP

// Store File object into DB:
        $newFile->dbsave();
        //LOKO RESIZE MOD **********************
        $ext substr$newFile->dget('name'), strrpos($newFile->dget('name'), '.') + ); //GETS THE EXTENSION
        $fullpath $newFile->get_full_path();
        if ($ext == "jpg" or $ext == "gif" or $ext == "png") {
            if ($ext == "jpg") { $src imagecreatefromjpeg($fullpath); }
            else if ($ext == "gif") { $src imagecreatefromgif($fullpath); }
            else if ($ext == "png") { $src imagecreatefrompng($fullpath); }
            list($width,$height)=getimagesize($fullpath);
            $newwidth=600;
            $newheight=($height/$width)*600;
            $tmp=imagecreatetruecolor($newwidth,$newheight);
            imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height);
            if ($ext == "jpg") { imagejpeg($tmp,$fullpath,100); }
            else if ($ext == "gif") { imagegif($tmp,$fullpath,100); }
            else if ($ext == "png") { imagepng($tmp,$fullpath,100); }
            imagedestroy($src);
            imagedestroy($tmp); 
        }
        //EOF LOKO MOD *************************

Nov 05, 2008 19:16

I realized that the resize was also resizing images smaller than 600px, so I added a conditional to take care of that.

PHP

//line 491 LOKO RESIZE MOD **********************
        $ext substr$newFile->dget('name'), strrpos($newFile->dget('name'), '.') + ); //GETS THE EXTENSION
        $fullpath $newFile->get_full_path();
        list($width,$height)=getimagesize($fullpath);
        if ($width 599 or $height 599) {
            if ($ext == "jpg" or $ext == "gif" or $ext == "png") {
                if ($ext == "jpg") { $src imagecreatefromjpeg($fullpath); }
                else if ($ext == "gif") { $src imagecreatefromgif($fullpath); }
                else if ($ext == "png") { $src imagecreatefrompng($fullpath); }
                $newwidth=600;
                $newheight=($height/$width)*600;
                $tmp=imagecreatetruecolor($newwidth,$newheight);
                imagecopyresampled$tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height );
                if ($ext == "jpg") { imagejpeg($tmp,$fullpath,100); }
                else if ($ext == "gif") { imagegif($tmp,$fullpath,100); }
                else if ($ext == "png") { imagepng($tmp,$fullpath,100); }
                imagedestroy($src);
                imagedestroy($tmp); 
            }
        }
        //EOF LOKO MOD *************************

Nov 06, 2008 05:06

It's nice to see this solved :)

Feb 14, 2009 04:09

Plugin updated to v0.4

New: each post may have its own directory for uploaded files (created automatically). No more mess in media folder and no more "the file already exists" errors.

Added pt_BR Brazilian translation. Thanks to Walter

Aug 12, 2009 06:48

1st Question:
I'm wondering how to change the default code block that says "<div class='image_block'>" etc? I've looked in upload_window.php and it looks like this is set around line 465, but I can't figure out how to get it to say what I want.

2nd Question:
I'm using my own addition which resizes the images upon upload (see my previous posts in this thread). I upgraded to version 0.4 and am now getting this error (the asterisks are for privacy):

Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 3072 bytes) in /****/****/public_html/blog/plugins/quick_upload_plugin/upload_window.php on line 507

Line 507 is the part of my own code that does the resizing:

Code

if ($ext == "jpg") { $src = imagecreatefromjpeg($fullpath); }

I've tried to set the upload_max_filesize, post_max_size, and memory_limit in php.ini to rediculously high amounts, but I still get the error. I have the php.ini file in the same directory as the upload_window.php file and I've also tried it in the root directory of the blog.

Thanks for any help. Here is the URL of my blog should you need it: http://www.oleniks.net/blog/lance.php

Aug 12, 2009 07:04

1
Edit the following code starting on the line 463

PHP

if( get_param('mode') == 'upload' )
{    // TODO: Add plugin hook to allow generating JS insert code(s)
    $img_tag format_to_output$newFile->get_tag(), 'formvalue' );
    $img_tag preg_replace'class="image_block"''class="my_class"'$img_tag );

Not tested

2
php.ini must be in your root directory.
"Allowed memory size of 33554432 bytes exhausted" means that the limit is 32M. If you want to deal with images set it to 64M.
Make sure your host reads the php.ini file, it may just ignore custom config.

Aug 13, 2009 01:00

Thanks sam2kb.

Unfortunately, it didn't work. What I mean is, it didn't replace the existing tag; it just left it as it was. Any other options or ideas?

I really appreciate the help.

Aug 13, 2009 01:02

My bad, change preg_replace to str_replace

Aug 23, 2009 06:15

Thanks again for the reply. Unfortunately, that didn't work either. I've figured out the memory error, but still can't change the input tag value to what I want. I actually want to replace this:
<div class="image_block"><img src="path/file.jpg" alt="" title="" width="480" height="320" /></div>

with this:

<a class="image_block" href="path/file.jpg" rel="lightbox"><img src="path/file.jpg" alt="" title="" /></a>

So its not just the class information, its the whole tag. I want to auto-add the lightbox functionality and remove the width/height, since I have that coded in the CSS.

Aug 23, 2009 07:54

Ok, so I'm not that great at PHP, but I figured out how to change the input value to what I want. In the original upload_window.php, I changed this code:

Code

if( get_param('mode') == 'upload' )
    {
      // TODO: Add plugin hook to allow generating JS insert code(s)
      $img_tag = format_to_output( $newFile->get_tag(), 'formvalue' );
      $success_msg .= '<ul>'
          .'<li><input type="text" value="'.$img_tag.'" size="50" /></li>'
          .'<li><a href="#" onclick="if( window.focus && window.opener ){ window.opener.focus(); textarea_wrap_selection( window.opener.document.getElementById(\'itemform_post_content\'), \''.format_to_output( $newFile->get_tag(), 'formvalue' ).'\', \'\', 1, window.opener.document ); } return false;">'.T_('Add the code to your post !').'</a></li>';

to this:

Code

$pathinfo = $newFile->get_full_path();
    $pathinfo = str_replace("/home2/olenikso/public_html", "http://www.oleniks.net",$pathinfo);
    $newimg_tag = "<a rel=&quot;lightbox&quot; class=&quot;image_block&quot; href=&quot;".$pathinfo."&quot;><img src=&quot;".$pathinfo."&quot; alt=&quot;&quot; title=&quot;&quot; /></a>";
    $newli_tag = "<li><input type='text' id='putinpost' value='.$newimg_tag.' size='50' /></li>";
      $success_msg .= '<ul>'
          .$newli_tag
          .'<li><a href="#" onclick="if( window.focus && window.opener ){ window.opener.focus(); textarea_wrap_selection( window.opener.document.getElementById(\'itemform_post_content\'), \''.$newimg_tag.'\', \'\', 1, window.opener.document ); } return false;">'.$this->T_('Add the code to your post !').'</a></li>';

Please give me suggestions on simplifying, if possible.

Aug 24, 2009 21:37

Try this

PHP

if( get_param('mode') == 'upload' )
{    // TODO: Add plugin hook to allow generating JS insert code(s)            
    $img '<img src="'.$newFile->get_url().'" '
            .'alt="'.$newFile->dget('alt''htmlattr').'" '
            .'title="'.$newFile->dget('title''htmlattr').'" '
            .' />';
    
    $img_tag '<a class="image_block" href="'.$newFile->get_url().'" rel="lightbox">'.$img.'</a>';
    $img_tag format_to_output$img_tag'formvalue' );
    
    $success_msg .= '<ul>'
etc...

Sep 13, 2009 21:54

Sam help!

I upgraded to v3.3 of b2 on two of my four blogs so far. On the first one this plug in is working fine but on the second (my main blog!) it's not.

I thought maybe there was a file issue so I deteled all the files and ran the upgrade again. I tried copying the files from the back of the blog that works fine. I downloaded the plug in again and reinstalled. I cleared the rendered cache under Misc but all I get is this when I click the button:

http://foreverpurple.com/images/quickupload.jpg

Sep 13, 2009 23:05

Are these blogs located on the same server?

Sep 18, 2009 16:28

Yes they are.

I'm having upload issues period. I'm starting to think my media folder is borked. I can't even change the permissions on it or delete anything.

I am going to try deleting it and see if the folders will recreate on their own.

Sep 18, 2009 17:13

I think you won't be able to delete it. Just download all pictures from it, create media2, and then upload all images back.

You can change media folder location from Blog setting > Advanced tab.

Sep 24, 2009 02:43

I can't delete anything in there, or I couldn't and I think it was a left over problem from the Avatars plug in. Anyway my webhost deleted it for me and now things are fine.

Sep 24, 2009 06:28

Avatars plugin creates new directories (Quick upload does it too), these directories belong to Apache user and may be not writable for hosting owner (you).

This depends on server configuration

Nov 05, 2009 17:32

All of a sudden today, the Quick Upload plugin is inserting uploaded images as links to the image file rather than putting the actual image in the blog post. I haven't made any changes to my b2evo configuration and my server PHP settings haven't been changed either. What's going on and how can I fix this?

Nov 05, 2009 17:50

tip for a next release (if any) :
quick upload checks if the post is saved allready, so it's behaving the same as the upload button under the post (that one is first saving the post and only then you can start uploading)

check if you are in html-mode and/or force the html-mode

Nov 05, 2009 17:54

If the post is not saved you can still upload and insert images into it, but they won't be put in a separate folder (if selected in plugin settings) and you won't be able [u]to link[/u] uploaded files.

Nov 05, 2009 17:58

sam2kb wrote:

If the post is not saved you can still upload and insert images into it, but they won't be put in a separate folder (if selected in plugin settings) and you won't be able [u]to link[/u] uploaded files.

I know,
It's exactly for those reasons I make the suggestions for a possible next release of the plugin.

I know I need to save first before I can link, but I seem to be unable to explain my co-authors. They keep insirting the image, and then I always have to go edit the post, delete the inserted image and make a link.

Nov 05, 2009 18:06

Thanks for the quick answers - first thing I checked was HTML/WYSIWYG mode. I checked again with our provider on PHP changes and turns out the shared server was clogged up with log files, so space had run out. As soon as those got cleared off, everything worked fine once more.

Nov 05, 2009 19:24

@tivogirl
Sounds good

@Topanga
There's no way to link an image to the post if we don't know post ID. And there's no ID assigned the the post until you save it. Same applies to default b2evo file manager.
What we can do is require users to save the post before opening an upload window.

Nov 06, 2009 01:36

sam2kb wrote:

There's no way to link an image to the post if we don't know post ID. And there's no ID assigned the the post until you save it. Same applies to default b2evo file manager.
What we can do is require users to save the post before opening an upload window.

I understand completely, no worries ;)

It's that in 3.3.1, when creating a new article, and when you want to attach/upload a file with the default fileuploader the button says : save and start uploading
Before you can start uploading, the article gets saved. And with that action, the article has a postID.
So you don't need to ask the user to save the post first, just do it, That way you ack as de core system. (if possible save the post as draft, but I will not argue for that.)

Nov 06, 2009 08:25

On my old blog, I could start writing a post and add images to it without saving it. Why was this changed in the new version?. If someone has publish check and writes a post and want to add an image and hits save to upload, the post will be published and pinged out when it is not finished. This is a bad thing. Who thought up this idea? This is a bad thing and it needs to be changed. The old way managed to work just fine and that is the way I want the new version to work. So what do I need to hack to get this working properly again. Saving and publishing a blog post that is not finished to upload images is a BAD thing, as it will ping out and people will start coming to a post that is not ready!

Nov 06, 2009 08:49

If the post is not saved [u]you can still upload and insert[/u] images into it, but they won't be put in a separate folder (if selected in plugin settings) and you won't be able to link uploaded files.

Nov 06, 2009 08:56

Kimberly wrote:

On my old blog, I could start writing a post and add images to it without saving it. Why was this changed in the new version?. If someone has publish check and writes a post and want to add an image and hits save to upload, the post will be published and pinged out when it is not finished. This is a bad thing. Who thought up this idea? This is a bad thing and it needs to be changed. The old way managed to work just fine and that is the way I want the new version to work. So what do I need to hack to get this working properly again. Saving and publishing a blog post that is not finished to upload images is a BAD thing, as it will ping out and people will start coming to a post that is not ready!

Thats why the core version has 'draft' as default.
But you can not link files to an unpublished post. For the reasons Sam has explained.
You can insert images though, so if you only insert images, and never linked your images, you don't have to worrie.

Nov 12, 2009 13:30

The download link seems to be dead for 0.4.

Nov 12, 2009 16:16

Fixed. Thanks a lot.
Seems like it was dead for about a month 8|

Nov 13, 2009 09:40

Thanks. :)

I have a small problem with translating the plugin. I made a new locale for Finnish and copied the Russian translation as the base. I then changed all the locale settings and translated the strings.

But when I try to use the translation, the scandinavian letters (ä, ö) don't display correctly.

I checked with other plugins and the main translation, and they seem to use the same settings.

For example in the post screen, all the other translation strings are displayed correctly but the quick upload strings aren't.

What could cause this?

Nov 13, 2009 14:08

What encoding do you use? Can you please PM me a link to your translation, I'll fix it and include in next release.

Nov 03, 2010 23:23

Plugin updated to v0.5

- Now supports b2evolution 4
- fixed minor bugs
- improved usability

Aug 22, 2011 16:28

Hi there,

the plugin works fine for me. But the code which is given out ("Add this to your blog post") is not fitting my needs perfectly. So I have to edit the code manually every time.
At first sight I did not find a way to change the outpu code. Could anyone give me a hint?

Kind regards, pgs

Aug 22, 2011 17:08

That code is not setup in the plugin, it's the default code b2evo creates. I can make it editable so one could change it in plugin settings.

Added in todo list.

Aug 22, 2011 22:25

Thanks a lot!

Kind regards, pgs

Jul 02, 2013 23:39

This plugin does not work in V504. Will there be an update?

Jul 03, 2013 01:28

image links in original post are broken. what is this plugin supposed to do which b2evo v5 doesn't do?

Jul 05, 2013 01:58

Basically I want to be able to upload files without having to save the post first. It's just a personal preference.

Jul 14, 2013 15:08

In addition to previous comment, now I remember another reason why I prefer using this plugin. One of my blogs is image intensive and has lots of files (1000+) in a directory. It takes time to load and takes time to filter through the list (I'm on a slow server) to locate files to be used for a given post. This plugin is quick as it doesn't display files and simplifies the upload process. It simply uploads and just display functions to insert the uploaded files. With what comes with V5, there are additional steps after popup - it lists file list, then I have to click upload tab to upload files, after files are uploaded I have to return back to browse tab to locate files to insert into post. Perhaps enhance the upload screen to provide links to quickly insert files to post?

Jul 15, 2013 17:38

We will enhance the upload process indeed.

Jul 21, 2013 18:23

I edited the post to show images

Jul 22, 2013 03:56

I updated the plugin, it should work in v5 now.


Form is loading...

powered by b2evolution free blog software – This forum is powered by b2evolution CMS, a complete engine for your website.