Joined: 20 Jun 2009
Posts: 344
Location: Portland Oregon
Posted: 11/23/09 12:22
I would like to be able to give users the ability to upload images with their classified ads. In order to do so, I would need to make sure that the image format is an allowed format for the users quota. It looks like the isMediaFile() function is the answer. The only issue is that I'm not sure I am using the proper arguments.
I tried to place the code below, during the error checking of the upload form.
$_post['meter_file_1'] is the File Upload form element
Code
// Error checking: Does the users quota allow this file format?
if (!isMediaFile($_post['meter_file_1'],'image',$_user['quota_image_formats'])) {
// do something!!!
}
Joined: 20 Jun 2009
Posts: 344
Location: Portland Oregon
Posted: 11/23/09 17:37
Thanks for the reply Kyle. I tried your suggestion, and it didn't work. Basically I am just trying to get the file uploading to work. With that in mind, I added 2 modes to my form controller, for testing purposes only. What I hoped would happen when this script is ran is:
ON mode=upload:
Display a simple form, with progress meter, that asks for the file to upload.
On the forms submit(mode=upload_done), the script should Iterate through the $_post['meter_file_1'] image array and echo the image attributes. (Name, type, tmp_name, error, & size) Then test the image to see if the file type is allowed by the users quota.
Everything seems to work great, until I get to the, 'Something went terribly wrong!'
Here is a snippet of form controller, Maybe you see something wrong?
Code
switch ($_post['mode']) {
case 'upload':
jmHtmlBegin('File Upload');
$_args = array(
'mode' => 'upload_done'
);
jrProgressFormBegin('mcClassifiedAds.php',$_args);
jmSpanCell('File Upload','This is the Help',30,'html_modify.png');
jmInput('Select a File',"meter_file_1",'file');
jrProgressBarHtml();
jrFormSubmit('Upload File','undo changes',false,'admin.php',false,true,'media');
jmEndForm();
jmBodyEnd();
jmHtmlEnd();
break;
exit;
case 'upload_done':
foreach($_post['meter_file_1'] as $key => $value) {
echo "-post['{$key}'] = '{$value}'<br/>";
}
echo "The files extension is: ". getExt($_post['meter_file_1']['name']) ."<br/>";
if (isMediaFile($_post['meter_file_1'],"image", $_user)) {
jrMediaGetFile("mcClassifiedAds","meter_file_1",'11',$_user['band_id']);
echo "saved?";
} else {
echo "something went terribly wrong!";
}