Joined: 20 Jun 2009
Posts: 344
Location: Portland Oregon
Posted: 12/06/09 01:07
I am not sure what I am doing wrong. I am trying to add image upload support for my classified ads module. So far, I have been successful with the following steps:
- displaying the form with the file upload input box.
- Validate the uploaded file.
IE verify the uploaded file is proper file type and have proper disk space.
-Using the JR jrMediaGetFile() function, actually upload the file.
uploaded to /media/BANDID/MEDIAID_MODULE_ad_image_file.EXTENSION
-Update/Insert the image information to database:
image_size, image_height, image_width, image_extension, image_name
Using filezilla, I have verified that the images are currently in the proper directory, or at least the directory they were uploaded to. Here is an example of what I am trying to do.
Here is a record from the ads table:
ad_id = 7
ad_band_id = 1
ad_title = 'This is merely a test ad'
ad_content = 'I hope this image upload works! Im gettin a bit frusterated!'
ad_image_size = 109386
image_height = 640
image_width = 480
image_extension = 'jpg'
image_name = '7_mcClassifiedAds_ad_image_file.jpg'
There is an image located at the following directory:
test/media/1/7_mcClassifiedAds_ad_image_file.jpg
Where test is the root folder for this jamroom install.
Keep in mind that my modules image.php script contains the following function:
Code
function mcClassifiedAds_AdImage($_args) {
global $jamroom_db;
if (!checkType($_args['media_id'],'number_nz') || !checkType($_args['band_id'],'number_nn')) {
return(false);
}
$req = "SELECT a.ad_image_size as image_size,
a.ad_image_height as image_height,
a.ad_image_width as image_width,
a.ad_image_extension as image_extension,
a.ad_image_time as image_time,
a.ad_image_name as image_name,
b.*,
q.*
FROM {$jamroom_db['mcAds']} a
LEFT JOIN {$jamroom_db['band_info']} b on b.band_id=a.ad_band_id
LEFT JOIN {$jamroom_db['quota']} q on q.quota_id=b.band_quota
WHERE a.ad_id = '{$_args['media_id']}'
AND a.ad_band_id = '{$_args['band_id']}'
";
$_rt = dbQuery($req,'SINGLE');
if (isset($_rt) && is_array($_rt)) {
return($_rt);
}
While investigating the error message, I noticed that the JR image.php script is looking for a default image in the image directory. So I went ahead and copied the "default_item_image.png" and uploaded the photo, with the following name, "default_AdImage.png"
Now the error went away. Instead I see a ton of symbols, numbers, letters etc. Much like what I would see, if I opened the image, using a text editor.
Any Suggestions, of help, would be great.
Thanks,
Tim
Joined: 09 Jul 2003
Posts: 37583
Location: Seattle, WA
Posted: 12/07/09 16:08
Make sure you are running the latest Jamroom 4.1.5 testing releases - support for default images for custom modules was added. You'll want to create a default image - i.e.
Where media_id refers to the unique ID of the ads table and the band_id refers to the creator of the ad. In this case, Ad_id = 7 contains the image information for the image I wish to display.
If I place a foreach loop in the mcClassifiedAds_AdImage function, just after the query is executed and stored into $_rt array:
Code
if (isset($_rt) && is_array($_rt)) {
// Test Loop: Lets see what is in the $_rt array?
foreach ($_rt as $key => $value) {
echo "{$key} = {$value}<br/>";
}
If I place the same loop in the JR image.php file(just after the module image function is called) I get the same info. So Its obviously receiving the data. I really appreciate all the help i've been getting from you and the rest of the Jamroom team & members.
Joined: 20 Jun 2009
Posts: 344
Location: Portland Oregon
Posted: 12/08/09 20:26
After changing my modules image function to the same name as the upload files(IE mcClassifiedAds_ad_image_file()) and typing in the following in to my browser address bar
I see that jamroom is trying to display the image. But instead of an image being displayed, I see what the image would look like, if I opened it in notepad, or similar text editor.
Joined: 20 Jun 2009
Posts: 344
Location: Portland Oregon
Posted: 12/16/09 20:33
hmm. Actually, with the link from the last post, it was a jpg. I have all my quotas set to allow png, jpg, gif files. I will try it with a png file though. Any suggestions on how to make it compatible with jpg and gif files?
something I did notice was occuring is, that when I upload the jpg file, and I click the link to the image.php script(that is generated by the htmlImageArea function in my modules form controller), that jamroom creates 2 more jpg's.
IE:
Original uploaded image:
10_mcClassifiedAds_ad_image.jpg
2 generated images by jamroom:
10_mcClassifiedAds_ad_image_w160_h120.jpg
10_mcClassifiedAds_ad_image_w640_h482.jpg
Also if I copy those files over to my desktop(including the original uploaded file), using filezilla, that they open just fine, when opened locally. So it seems that the files wouldn't be corrupt.