Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: [MOD_HELP] Advanced image/file upload mod.  (Read 4676 times)

George Antoniadis

  • Sr. Member
  • ****
  • Karma: 0
  • Posts: 479
[MOD_HELP] Advanced image/file upload mod.
« on: April 23, 2006, 01:17:30 am »

Since I'm allready working on 2-3 mods I don't have much time for another but I think it's kinda usefull for a lot of ppl...
An advanced file uploader mod...

User can have the ability to upload a range or files, create directorys, subdirectories etc, view images as thumbnails, resize pictures, etc...
If anyone is interested in helping on this please let me know! ^_^
Luka you do your thing! :P - This won't have much js hehe! ;)
Logged
How I feel like I'm starless, I'm ready to fade now.
And how I feel like I'm starless, I'm hopeless and greyed out.

mejobloggs

  • Full Member
  • ***
  • Karma: 0
  • Posts: 125
[MOD_HELP] Advanced image/file upload mod.
« Reply #1 on: May 17, 2006, 08:26:13 am »

I will give it a shot. I think it will take me a while though, but hopefully I can do a lot of work on it in the weekends.
Logged

Patric Ahlqvist

  • Nobodys perfect, but Im pretty effing close
  • ULTIMATE member
  • ******
  • Karma: 65
  • Posts: 4867
  • I'm a self-made man and worships my creator.
    • p-ahlqvist.com
[MOD_HELP] Advanced image/file upload mod.
« Reply #2 on: May 17, 2006, 08:54:01 am »

Ok, I don't know the first thing about PHP, but I had this uploader lying about...Could it be something ? Or atleast something to origin from ?

Code: [Select]

if($pwd=="TEST"){
setcookie("pwd",$pwd);




// UPLOAD


if(!$userfile){



echo "
Upload



Folder:









File:




Take me to the uploaded file









Logout

";

}
else {
$dir=$folder;
if($dir){$dir_done=$dir;}
else {$dir="";}

$filename=basename($userfile_name);
copy($userfile,$dir_done.$filename);



echo "$filename Uploaded

";
}


}
else {
if($pwd){echo "wrong password

";}
echo "

Password:
";
}
Logged
"It's only dead fish that goes with the flow... "
Updated

Keyrocks

  • Doug
  • ULTIMATE member
  • ******
  • Karma: 449
  • Posts: 6020
  • Semantically Challenged
    • snews.ca
[MOD_HELP] Advanced image/file upload mod.
« Reply #3 on: May 17, 2006, 05:38:33 pm »

Hmmm... we can already upload all file types to the img folder using the image uploader. Let's say we want to make a .zip file available to site visitors, that's easy to do by just using a link to it using the filepath thru the img folder. The downside is that non-image files are listed in the image drop-down in the New Article admin panel, though we can also delete them from there as well.

I've been using a php uploader as a separate file in other sites (in the root directory), uploading to an separate storage folder in the same location. It doesn't require any JS. Only downside is that it doesn't include a way of deleting files without actually going into the folder and deleting them manually.

These posts urged me to try it this a.m. in sNews' root and it worked just fine (offline testing). I'll now try to see if I can add it as an an additional admin function to snews.php and see how that works.

analyzerx - my php & js skills are limited but I would think - and it's just a thought - that each of the functionalities you suggest would need to be separate functions located either in snews.php or a separate .php file like "morefunctions.php" and called from there. I do not think they could all be combined in one function, n'est pas? :)

Added May 20/06
As an update to this post, I ended up creating a function for sNews 1.4 that uploads any file to the site. Maybe you can make use of it - I posted it a couple days ago here - http://www.solucija.com/forum/viewtopic.php?id=949
Logged
Do it now... later may not come.
-------------------------------------------------------------------------------------------------
sNews 1.6 MESU | sNews 1.6 MEMU

mejobloggs

  • Full Member
  • ***
  • Karma: 0
  • Posts: 125
[MOD_HELP] Advanced image/file upload mod.
« Reply #4 on: May 19, 2006, 01:55:51 pm »

Well, here is my contribution so far....

Code: [Select]
/*
$sourceImage = name of the original file that the thumbnail is created from
$targetImage = name of the ouput file
$forcedWidth = constrains the output file to this width
$forcedHeight contrains the output file to this height
$keepWHRatio = Keep Width/Height Ratio. With this turned on, you only have to specify either
height or width, and the other will resize proportianally. (default = true)
I think this is also called Keep Aspect Ration?? If it is, then that would
be a better name for the variable.
$jpegQuality = quality of the jpeg (0 worst, 100 best, default 75 (recommended))
$deleteOriginal = If you want to delete the original, then input a 1 here.
This is for image upload/convert 'on the fly' sort of thing,
and it will delete the image uploaded, and replace it with a new
image according to your settings. (default = false)
 */
function resizeimgtojpeg ($sourceImage, $targetImage, $forcedWidth, $forcedHeight, $keepWHRatio = true, $jpegQuality = 75, $deleteOriginal = false)
{
if(file_exists($sourceImage))
{
if ($keepWHRatio == true)
{
$sourceSize = getimagesize($sourceImage);

// For a landscape picture or a square
if ($sourceSize[0] >= $sourceSize[1])
{
$finalWidth = $forcedWidth;
$finalHeight = ($forcedWidth / $sourceSize[0]) * $sourceSize[1];
}
// For a potrait picture
else
{
$finalWidth = ($forcedHeight / $sourceSize[1]) * $sourceSize[0];
$finalHeight = $forcedHeight;
}
}
else
{
$finalWidth = $forcedWidth;
$finalHeight = $forcedHeight;
}

$sourceID = imagecreatefromstring(file_get_contents($sourceImage));
$targetID = imagecreatetruecolor($finalWidth, $finalHeight);
$target_pic = imagecopyresampled($targetID, $sourceID, 0, 0, 0, 0 , $finalWidth, $finalHeight, $sourceSize[0], $sourceSize[1]);
imagejpeg($targetID, $targetImage, $jpegQuality);
imagedestroy($targetID);
imagedestroy($sourceID);

if ($deleteOriginal && file_exists($sourceImage))
{ unlink($sourceImage); }

return true;
}

else { return false; }
}
?>
Probably buggy cause I havn't been able to test it yet, but it's getting there :)

**Woop, found I have a uni assignment. The complete mod will come sometime after that.
Logged

mejobloggs

  • Full Member
  • ***
  • Karma: 0
  • Posts: 125
[MOD_HELP] Advanced image/file upload mod.
« Reply #5 on: August 05, 2006, 10:56:03 am »

Progress so far: http://www.icebytes.co.nz/misc/screenie.png

It's going reeaally slow, but I have managed a wee bit. Sorry about that.

A question. How do I deal with error handling? Do I do it all through javascript?
Logged

Mika

  • Hero Member
  • *****
  • Karma: 9
  • Posts: 1377
    • http://www.ni5ni6.com/
[MOD_HELP] Advanced image/file upload mod.
« Reply #6 on: August 05, 2006, 12:50:40 pm »

only if you're 100% sure that JS is enabled in user's browser
Logged
http://www.ni5ni6.com/ - Tutorials, Mods and How-To's about sNews CMS
sNews 1.6 Developers Edition - commented sNews 1.6 version

mejobloggs

  • Full Member
  • ***
  • Karma: 0
  • Posts: 125
[MOD_HELP] Advanced image/file upload mod.
« Reply #7 on: August 06, 2006, 02:39:25 am »

Hmf, well JS error handling is so much easier.
Logged