Watch
GitHub Core
Show your support for Zikula! Sign up at Github account and watch the Core project!
GitHub Modules
- rgasch created topic »Using PageUtil::addVar() to load script code« 11:48 AM
- michiel responded to »password problem« 10:01 AM
- mazdev responded to »Hide "Register new account" and change template to 3 col« 07:50 AM
- mesteele101 created topic »Zikula 1.3.3 - Site Search 1.5.2 - Unable to turn off plug-ins« 07:48 AM
- mesteele101 responded to »ERR (3): E_USER_ERROR: Smarty error: [in pagesvar:pagesitem2en line XXX]…« 25. May
- mazdev responded to »Pages 2.5.0 and updating - Page not found« 25. May
- mesteele101 responded to »Zikula 1.3.3 - Selecting a category in Pages not working« 25. May
Zikula Blog
- Anatomy of Open Source Projects on Mar 07
- Continuous Review on Mar 01
- Not Invented Here on Feb 24
- How to Contribute Your Code at Github on Jan 13
- 10 Steps to Coding-Nirvana: Tips for Successful Module Writing on Nov 12
- Submitting Bug Report Tickets That Get Results on Aug 17
- Cozi Tricks #1: Syntax Highlighting on Aug 07
Login
FileUtil::uploadFile
-
- Rank: Registered User
- Registered: Dec 02, 2007
- Last visit: Oct 21, 2009
- Posts: 40
Hi, i want to receive a picture from a form and upload it. please help me that can i upload it via uploadFile? and please tell me that how can i resize that picture then upload it. -
- Rank: Team Member
- Registered: Jan 05, 2003
- Last visit: May 28, 2010
- Posts: 776
Try the following:
Code
$rc = FileUtil::uploadFile ('filekey', 'some/directory');
where filekey is the name under the $_FILES array which contains the reference to the file you want to upload.
As for generating thumbnails (or just resizing the image), you will have to write some custom code which calls the Thumbnail module.
Greetings
R -
- Rank: Developer
- Registered: Mar 29, 2005
- Last visit: Mar 13, 2010
- Posts: 228
This is a sketch of how the code should look like:
Code
$rc = FileUtil::uploadFile ('uploadkey', $path.$name);
$image = array();
$image['srcFilename'] = $path.$name;
$image['dstFilename'] = $path.$newname;
$image['w'] = $width;
$image['h'] = $height;
pnModAPIFunc('Thumbnail', 'user', 'resizeImage', $image);
Basically srcFilename must be the path to the image u just uploaded, dstFilename must be the path (and name) where u want to save the resized image, w and h are the sizes of the image after the resizing.
Please note that Thumbnail doesn't work out of the box but need a little bit of configuration.
--
Zikula Italia
SimpleGallery -
- Rank: Helper
- Registered: Dec 31, 1969
- Last visit: May 07, 2010
- Posts: 507
Arthens
Please note that Thumbnail doesn't work out of the box but need a little bit of configuration.
What kind of configuration? I tried to get it to work with Pagesetter documents, which have query style URLs rather than actual paths, and it wouldn't work. However the underlying utility it uses does this just fine. I was thinking maybe it was a bug in the Zikula module portion of it, but maybe I have missed some configuration? -
- Rank: Registered User
- Registered: Dec 02, 2007
- Last visit: Oct 21, 2009
- Posts: 40
thank you for your help. i have two questions.
1- what is destination? for example i install zikula in public_html/zikula and i want to upload my picture or file to modules/test/uploads please tell me that how to write detination
2- if fileUtil encounter with an error, how can i read that? i echo $RC but it doesn't any value.
thank you again. -
- Rank: Developer
- Registered: Mar 29, 2005
- Last visit: Mar 13, 2010
- Posts: 228
bronto
What kind of configuration?
IIRC in modules/Thumbnail/includes/phpThumb/ you have to rename phpThumb.config.php.default to phpThumb.config.php
based on the configuration of your server you may also need to change some settings
--
Zikula Italia
SimpleGallery -
- Rank: Developer
- Registered: Mar 29, 2005
- Last visit: Mar 13, 2010
- Posts: 228
msshams
1- what is destination? for example i install zikula in public_html/zikula and i want to upload my picture or file to modules/test/uploads please tell me that how to write detination
sorry, there was an error in my previous code, the right one is:
Code
$rc = FileUtil::uploadFile ('uploadkey', $destination, $name);
in your case $destination should be
Code
$destination = "modules/test/uploads/";
msshams
2- if fileUtil encounter with an error, how can i read that? i echo $RC but it doesn't any value.
$RC is a boolean value, because the function move_uploaded_file returns true or false.
Unfortunately the reason of the failure is issued with a warning, so you have to find out yourself what went wrong (check that the destination folder is writable)
BTW I opened a ticket suggesting to improve the output of FileUtil::uploadFile();
http://code.zikula.org/core/ticket/1272
--
Zikula Italia
SimpleGallery -
- Rank: Registered User
- Registered: Dec 02, 2007
- Last visit: Oct 21, 2009
- Posts: 40
-
- Rank: Registered User
- Registered: Dec 02, 2007
- Last visit: Oct 21, 2009
- Posts: 40
but when i try to resize uploaded image, it shows an error. you can find it here: http://paste.ubuntu.com/269095/
i write these lines: http://paste.ubuntu.com/269096/
can you tell me that what is problem? thank you. -
- Rank: Developer
- Registered: Mar 29, 2005
- Last visit: Mar 13, 2010
- Posts: 228
It looks like there is a problem with the file you are uploading, because there is this error:
Code
setSourceFilename(modules/RoseateMem/portrait/25.png) set $this->sourceFilename to "modules/RoseateMem/portrait/25.png" in file "phpthumb.class.php" on line 243
file_exists() = 0 in file "phpthumb.class.php" on line 1099
is_executable() = 0 in file "phpthumb.class.php" on line 1100
file_exists() = 0 means that the file does not exist. Are you sure that the file has been uploaded? if you look in the folder modules/RoseateMem/portrait/ is the file 25.png there?
--
Zikula Italia
SimpleGallery -
- Rank: Developer
- Registered: Mar 29, 2005
- Last visit: Mar 13, 2010
- Posts: 228
BTW I just noticed that what I told you before was not 100% correct. The variable $RC is not boolean, but still it's not really reliable because it covers only few errors. If it contains an error it means that the upload failed, but if it's empty it doesn't mean the the upload was fine. For example if it fails to upload the file (technically it just moves it) because the destination folder is not writable it fails without any error.
So basically it's fine to check it, just be aware that in some situations it fails without telling you that it happened.
What you can do is to add this lines:
Code
if (!file_exists("modules/RoseateMem/portrait/".$memberinfo['pid'].".png")) {
// upload failed, do something
}
after:
Code
$rc = FileUtil::uploadFile ('pic', 'modules/RoseateMem/portrait',$memberinfo['pid'].".png");
By this way you can be sure that the upload succeeded, and if it didn't you can return an error message or whatever
--
Zikula Italia
SimpleGallery -
- Rank: Registered User
- Registered: Dec 02, 2007
- Last visit: Oct 21, 2009
- Posts: 40
Arthens
file_exists() = 0 means that the file does not exist. Are you sure that the file has been uploaded?
yes, it's uploaded. i changed code to this: http://paste.ubuntu.com/269604/
also when i see content of 'portrait' folder i see uploaded pictures. do you have another idea? thank you again for your replies. -
- Rank: Developer
- Registered: Mar 29, 2005
- Last visit: Mar 13, 2010
- Posts: 228
msshams
yes, it's uploaded. i changed code to this: http://paste.ubuntu.com/269604/
this code is wrong, you have to add an exclamation point before file_exists
what you want to do is something like "if the file does not exist then exit", but if you omit the exclamation point you obtain "if the file exists then exit"
anyways, if you correct the script (adding the !) and try to upload the image what happens?
do you still get the error message of Thumbnail? Same as before?
--
Zikula Italia
SimpleGallery -
- Rank: Registered User
- Registered: Dec 02, 2007
- Last visit: Oct 21, 2009
- Posts: 40
thank you. i changed my code to this, but still 'ERROR' doesn't echo.
Loader::loadClass('FileUtil');
$RC = FileUtil::uploadFile ('pic', 'modules/RoseateMem/portrait',$memberinfo['pid'].".png");
if (!file_exists("modules/RoseateMem/portrait/".$memberinfo['pid'].".png")) {
echo "error";
exit;
} -
- Rank: Developer
- Registered: Mar 29, 2005
- Last visit: Mar 13, 2010
- Posts: 228
Are you sure that Thumbnail is correctly configured? Check the administration page, if there is a problem with the module it should be written there.
Also, have you moved the website from a server to another? Or from localhost to a live webserver?
If it's like I'd like to investigate the problem personally
--
Zikula Italia
SimpleGallery
- Moderated by:
- Support
