Post by hm2k » Fri Dec 19, 2008 12:45 am

As mentioned in a previous thread, in a previous project that used attachments we initially had 1 attachment box, mainly for the sake of design, but I came up with this solution where you could simply add another input box underneath:

Code: Select all

<!-- attachments start -->
<br>
	<input type="file" name="attachment" id="attachment" onchange="document.getElementById('moreUploadsLink').style.display = 'block';" />
	<div id="moreUploads"></div>
	<div id="moreUploadsLink" style="display:none;"><a href="javascript:addFileInput('moreUploads');">Attach another File</a></div>
<!-- attachments end -->

Code: Select all

<script language="javascript" type="text/javascript">
//add/remove upload files
var upload_number = 1;
function addFileInput(i) {
	if(upload_number > 10) { return; } //no more than 10
	var d = document.createElement("div");
	var l = document.createElement("a");
	var file = document.createElement("input");
	file.setAttribute("type", "file");
	file.setAttribute("name", "attachment"+upload_number);
	l.setAttribute("href", "javascript:removeFileInput('f"+upload_number+"');");
	l.appendChild(document.createTextNode("Remove"));
	d.setAttribute("id", "f"+upload_number);
	d.appendChild(file); d.appendChild(l);
	document.getElementById(i).appendChild(d); upload_number++;
}

function removeFileInput(i) {
	var elm = document.getElementById(i);
	document.getElementById("moreUploads").removeChild(elm);
	upload_number = upload_number - 1; // decrement the max file upload counter if the file is removed
}
</script>
Also see: "Uploading Files Like GMail Attachments" -> http://www.petefreitag.com/item/587.cfm

Something like this could easily be added in for images, the PHP backend code is already pretty much there to handle multiple files (may need a little tweaking), it's just the frontend HTML that lacks the support.

This is an idea for 0.8.

Comments welcome.
Last edited by hm2k on Wed Jan 21, 2009 7:58 pm, edited 1 time in total.

UK Web Hosting


User avatar
Global Moderator

Posts

Joined
Tue Mar 11, 2008 9:06 am
Location - UK

Post by hm2k » Wed Feb 04, 2009 8:01 pm

I had another idea, based around the ftp upload idea and the auto-detect extensions.

There are two main tables for images (the others are linking tables):
* image:image_id,filename,date_added
* image_description:image_id,language_id,title

* id will be created when it's added
* filename is unique, based on the image filename
* date_added will be created when it's added
* language_id we can guess from the default language
* title can be generated from the filename by stripping the extension, replacing _- with a space, and using ucwords().

The idea is that when you go to the images page, it will run a check, if a filename in the filesystem doesn't appear in the database, it call an init() function to initialise the image into the database.

UK Web Hosting


User avatar
Global Moderator

Posts

Joined
Tue Mar 11, 2008 9:06 am
Location - UK

Post by Qphoria » Wed Feb 04, 2009 8:18 pm

I think tthis check/init thing is the dawn of a whole new revolution :)

Image
Donate!|OpenCart Basics|GeoZones
Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by hm2k » Wed Feb 04, 2009 8:31 pm

Yatta! Success! It works! :)

When you visit the image page in the admin area, all images in the "image" directory that you have uploaded via ftp and aren't already in the database will be loaded into the database automagically!

r425, going public.

Do we still need the "html based multiple image uploader" mentioned before as well?

UK Web Hosting


User avatar
Global Moderator

Posts

Joined
Tue Mar 11, 2008 9:06 am
Location - UK

Post by Qphoria » Wed Feb 04, 2009 8:38 pm

perhaps some way of uploading multiple files from the admin area. some sort of cool file upload tool for those who installed opencart via fantastico and aren't familiar with ftp... maybe not needed right now.

Image
Donate!|OpenCart Basics|GeoZones
Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by hm2k » Wed Feb 04, 2009 10:32 pm

I guess the HTML method I posted would support that as much as can be anyway.

PHP has upload limits, so you can't really upload that much at once via HTML anyway.

So I guess it's not that important right now.

UK Web Hosting


User avatar
Global Moderator

Posts

Joined
Tue Mar 11, 2008 9:06 am
Location - UK

Post by Qphoria » Wed Feb 04, 2009 10:41 pm

Would be nice if we could add an autounzipper for things. like upload a zip file of images that auto unzip when they get uploaded to squeeze more into the php limiter.

Maybe in the future if we get a "package system" in place where we can upload a zip and it autoinstalls everything for you, that could be part of it for like "image packs" or something.
Just thinking out loud.
Last edited by Qphoria on Wed Feb 04, 2009 10:42 pm, edited 1 time in total.

Image
Donate!|OpenCart Basics|GeoZones
Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by hm2k » Wed Feb 04, 2009 10:53 pm

What we could do, is if a zip file is found in the upload dir, the script could unzip it first, then run the rest of the checkFiles, which in turn will then run init() for each new file.

Seems a bit overkill really, considering you must be uploading multiple images, have no ftp access or don't know how to use it, have a zip file of images, totalling under the php upload limit (usually about 5mb).

I think most people would just opt for FTP, after all if you understand how to zip, i'm sure you can figure out ftp right?

UK Web Hosting


User avatar
Global Moderator

Posts

Joined
Tue Mar 11, 2008 9:06 am
Location - UK

Post by Qphoria » Wed Feb 04, 2009 10:55 pm

hm2k wrote: after all if you understand how to zip, i'm sure you can figure out ftp right?
::) First day here? :P

Image
Donate!|OpenCart Basics|GeoZones
Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by jty » Thu Feb 05, 2009 3:26 pm

hm2k wrote: When you visit the image page in the admin area, all images in the "image" directory that you have uploaded via ftp and aren't already in the database will be loaded into the database automagically!
hm2k, you are brilliant !!!!!!!!!
I applied r425 to RC3, yes I said RC3 on my xammp copy
Only problem is the line

Code: Select all

$str=pathinfo_filename($file);
Which isn't a problem for me because I don't use image titles so I just made it the same as the filename
Haven't tried it on the live server though

Thank-you, thank-you, thank-you

jty
Active Member

Posts

Joined
Sat Aug 30, 2008 8:19 am

Post by hm2k » Thu Feb 05, 2009 6:23 pm

You need the library/common/pathinfo_filename.php file.

I accept donations :)

UK Web Hosting


User avatar
Global Moderator

Posts

Joined
Tue Mar 11, 2008 9:06 am
Location - UK
Who is online

Users browsing this forum: No registered users and 3 guests