-
giori
-
-
Offline
-
Senior Member
-
- Posts: 73
- Thank you received: 14
-
Karma: 6
-
|
I have a simple project 'helloworld' to test image and file uploading. Image uploading is OK, file uploading produces the following error:
Mime type not valid (application/force-download), allowed Mimes are application/msword - text/html - image/jp2 - image/jpeg - application/pdf - image/png - image/psd - text/rtf - application/x-gzip - image/tiff - text/plain - image/xbm - application/x-zip :
There were some upload errors
As it coud be as suggested an Apache problem, here my data:
Using Wampserver 2.1 on Windows 7 Ultimate x64 with the following subset:
Apache Version 2.2.17
PHP Version 5.3.4
MySql Version 5.1.53
|
|
-
admin
-
-
Offline
-
Administrator
-
-
Chef
- Posts: 3711
- Thank you received: 987
-
Karma: 140
-
|
application/force-download Means that the mime-type hasn't been recognized.
Try to have a look in the classes/file.php in the getMime() function.
There are few different ways to get such informations, but also many variations of availability of theses functions. In the mentioned function, you can find, and add, a method that worked on you server.
May also have a look in the com_media classes or helpers to understand how the mime is decoded if it works.
Very busy now.
And please share if you find something nice.
Thanks
|
Coding is now a piece of cake
|
-
giori
-
-
Offline
-
Senior Member
-
- Posts: 73
- Thank you received: 14
-
Karma: 6
-
|
So, do you mean that I have to change the php code to upload .doc or .pdf files? There is no entry for .doc or .pdf in file.php.
I can upload in the sandbox, but not in localhost.
Also there is an error with the COM_SITE variable. In my case the base path is: /joomla17/sitename, but when an image is saved, a folder sitename/components/com_helloworld/files is created in /joomla17 instead of /joomla/sitename.
|
|
-
shail
-
-
Offline
-
New Member
-
- Posts: 19
-
Karma: 0
-
|
In cook j-pro there are possible to upload pdf and doc, tar, zip etc. there are in Data fields select the edit validator there are selection which type of files are uploading and what the size of file.
|
|
-
giori
-
-
Offline
-
Senior Member
-
- Posts: 73
- Thank you received: 14
-
Karma: 6
-
|
Hi shail,
I can upload in the sandbox, but not in localhost.
Being able to upload in the sandbox obviously means that the component was composed correctly. So there must be some other reason for not being able to upload. Also I installed the component on a pristine standard untouched Joomla 1.7.3 with no alterations.
|
Last Edit: 13 Jan 2012 11:21 by giori.
|
-
shail
-
-
Offline
-
New Member
-
- Posts: 19
-
Karma: 0
-
|
Hi,
Its uploading in localhost also, if you use linux there can be some problem of permission, otherwise its working, please refresh file list and run the sandbox, if its working there. So, Its also working in localhost..
|
|
-
giori
-
-
Offline
-
Senior Member
-
- Posts: 73
- Thank you received: 14
-
Karma: 6
-
|
I regenerated my test component, downloaded and installed again and tested it. I found the following:
1. There is an error in creating the standard image file path. My test site is located at
/localhost/joomla17/joomla
But the image file path is created at:
/localhost/joomla/components/com_helloworld/files/...
instead of
/localhost/joomla17/joomla/components/com_helloworld/files/...
2. I can upload image files both from the image picker and from the file picker as well.
3. I cannot upload .doc and .pdf files neither in the frontend nor in the backend on localhost, but I can upload them in the sandbox.
As this small hello_world project is just being used for testing functionalities and I do need the uploading functionality right away, I won't dig into the problem any longer and hope the bugs will be fixed some time in the future.
|
|
-
admin
-
-
Offline
-
Administrator
-
-
Chef
- Posts: 3711
- Thank you received: 987
-
Karma: 140
-
|
Hi giori,
Sorry for coming late.
Can you upload other files types ?
Images for example ?
I solve your problem today.
|
Coding is now a piece of cake
|
-
admin
-
-
Offline
-
Administrator
-
-
Chef
- Posts: 3711
- Thank you received: 987
-
Karma: 140
-
|
I checked yout problem N°1, and for me it is working.
Let's concentrate first on the problem of upload.
Can you open your classes/upload.php file and comment theses lines :
function uploadFile($uploadFile, $options = array())
{
[...]
/*
//CHECK MIME HEADER
$this->file->mime = $this->getMime($this->file->tmp);
if (!$this->checkMime($this->file->mime))
{
$app->enqueueMessage(JText::sprintf(
"FOREIGNKEYS_UPLOAD_MIME_TYPE_NOT_VALID_ALLOWED_MIMES_ARE",
$this->file->mime,
$this->getAllowedMimes()), 'error');
return false;
}
*/
And tell me if you can upload
|
Coding is now a piece of cake
Last Edit: 14 Jan 2012 12:55 by admin.
|
-
giori
-
-
Offline
-
Senior Member
-
- Posts: 73
- Thank you received: 14
-
Karma: 6
-
|
Hi Jocelyn,
making some progress. As I mentioned before, uploading of image files was OK, both as image upload and as file upload.
Now after commenting out the function mentioned by you, I can upload .doc and .pdf files as well, but....
They are displayed without extension, so a file named xxx.doc is displayed as xxx. and it is saved as xxx
They are still saved one level below the base path, so problem No 1. persists.
|
Last Edit: 14 Jan 2012 13:31 by giori. Reason: Removed dot at the end of second xxx
|
-
admin
-
-
Offline
-
Administrator
-
-
Chef
- Posts: 3711
- Thank you received: 987
-
Karma: 140
-
|
The file extension come from the mime type.
The mime type of your files are not recognized, so the extension is blank when you skip the mime check.
You can setup this in the properties (Rename file), and keep the original file extension. {BASE}.{EXT}
Well,
If you can upload images, that means that getMime() function is working.
How many different files did you tried ? (DOC and PDF).
Do you have image magik installed on your php ?
Look in your classes/file.php :
function getMime($file)
{
[...]
//prefered order methods to call the mime decodage
$mimeMethods = array(
'mime_content_type', // <- THIS IS FOR IMAGE MAGIK
'finfo_file',
'image_check',
'system',
'shell_exec',
);
Try to comment 'mime_content_type'
|
Coding is now a piece of cake
|
-
giori
-
-
Offline
-
Senior Member
-
- Posts: 73
- Thank you received: 14
-
Karma: 6
-
|
Hi Jocelyn. commenting out the 'mime_content_type' did not change anything.
No, I do not have image magik. Be aware, I am doing everything locally on a Windows 7 x64 PC. Besides Office 2010, I have IrfanView, Paint.Net and FastStone as image viewer installed.
I tried uploading .doc, .pdf, .jpg., .png files. It's always the same effect. Also be aware, I did not change any upload properties.
As I run Wampserver on a Windows PC, could it be that some addon-libraries or modules in Apache or Php be missing?
|
|
-
admin
-
-
Offline
-
Administrator
-
-
Chef
- Posts: 3711
- Thank you received: 987
-
Karma: 140
-
|
Image magik is an apache library.
The programs that runs on your computer cannot interract.
I said that is still the same effect even uploading .jpg, .png ?
now try this :
foreach($mimeMethods as $method)
{
if (!$mime) // <- ADD THIS
switch($method)
{
EDIT : Imagemagik is not required, I asked just the question to understand if it could be a conflict.
|
Coding is now a piece of cake
Last Edit: 14 Jan 2012 15:02 by admin.
|
-
giori
-
-
Offline
-
Senior Member
-
- Posts: 73
- Thank you received: 14
-
Karma: 6
-
|
Hi Jocelyn,
nothing changed. Can still upload, but no extension is displayed and the files are saved without extension.
With his changes Ican upload both image files and doc files as well, but all the extensions are stripped.
I assume, that I don't have to revoke any of the previous changes. If I have to, please tell me if I have to revoke any changes.
Will be around for another 40 minutes.
|
|
-
admin
-
-
Offline
-
Administrator
-
-
Chef
- Posts: 3711
- Thank you received: 987
-
Karma: 140
-
|
Well, excuse me I wasn't very precise.
If you want the extension of your file it is very easy :
In the table's controller, you have something like this : if (!$this->_upload('my_image', &$post, array(
'image/bmp' => 'bmp',
'image/gif' => 'gif',
'image/jpeg' => 'jpg,jpeg',
'image/png' => 'png')
, array(
'overwrite' => 'no',
'rename' => '{RAND}.{MIMEXT}', // HERE set {BASE}.{EXT} or {ALIAS}.{EXT}
)))
because {MIMEXT} extract extension from the detected mime-type, which is more clever.
BUT :
Our problem is not here. It is very important to check the mime of a file.
So please remove all comments I asked you todo, and just do the only and last operation wich is :
foreach($mimeMethods as $method)
{
if (!$mime) // <- ADD THIS
switch($method)
{
If this is not working, I cannot help you more. It is your apache that is missing something.
So in localhost, don't check mime type, and in production, restore the source code.
|
Coding is now a piece of cake
|
|