Hi,
I'm trying to expand this mods functionality to have more than one download-directory (with different picture-sizes therein) and let the user choose via selction-formular which size to download on the details-page.
My approach seemed quiet simple to me: just use a variable instead of the phrase "/download" where the download-path is defined and assign the name of the choosen download-directory to this variable via the formular.
Unfortunately this failed because I could not succeed to declare the variable as global, so that it is accessible from other parts of the script. So the main question for me is at the moment: How can I define a variable as global and accessible for the whole script?
I asked this Question in another thread 4homepages. de/forum/index. php?topic=26033. 0 and V@no thankfully gave me some answers, but at least I couldn't solve the problem so I follow the advice to post the problem here and give more details.
As you see, I'm just a beginner in php but very experienced in other scripts like vb and in html and css, too.
Here is what I did:
in includes/funktions. php I modified the original mod
$check_handle = "check_". $image_type. "_type";
//-----------------------------------------------
//-- MOD Alternative Download Directory ---------
// $path = (($image_type == "media") ? (($cat_id) ? MEDIA_PATH. "/". $cat_id : MEDIA_TEMP_PATH) : (($cat_id) ? THUMB_PATH. "/". $cat_id : THUMB_TEMP_PATH)). "/". $file_name;
// return ($check_handle($file_name) && file_exists($path)) ? (($in_admin && !preg_match("#(gif|jpg|jpeg|png)$#is", $file_name)) ? ICON_PATH. "/". get_file_extension($file_name). ". gif" : $path) : $return_code;
// Download file block insert BEGIN
switch( $image_type ) {
case "media":
if( $cat_id )
$path = MEDIA_PATH. "/". $cat_id;
else
$path = MEDIA_TEMP_PATH;
break;
case "big":
$path = MEDIA_PATH. "/". $cat_id. "/big";
break;
case "download":
$path = MEDIA_PATH. "/". $cat_id. "/download";
echo $path;
break;
default:
if( $cat_id )
$path = THUMB_PATH. "/". $cat_id;
else
$path = THUMB_TEMP_PATH;
break;
}
$path . = "/". $file_name;
// Download file block insert END
return ($check_handle($file_name) && file_exists($path)) ? (($in_admin && !preg_match("#(gif|jpg|jpeg|png)$#is", $file_name)) ? ICON_PATH. "/". get_file_extension($file_name). ". gif" : $path) : (($image_type != "big" && $image_type != "download") ? $return_code : ""); // Download file :: V@no big mod
to
$path = MEDIA_PATH. "/". $cat_id. $dp_download_folder; // changing the original phrase "/download" to a varibale
where $dp_download_folder is the variable for the download-directory and should contain e. g. "/download" or any other directory with different size of the picture.
This Variable I declared as global at top of the function:
function get_file_path($file_name = "", $image_type = "media", $cat_id = 0, $in_admin = 0, $return_icon = 1, $check_remote = CHECK_REMOTE_FILES) {
global $dp_download_folder;
When I assign $dp_download_folder = "/med", e. g. at the top of global. php, the download-button at the details-page will succesfully download from this directory.
I now set up a form in details. html of my template wich should choose the picture-size and set $dp_download_folder
(. . . )
<?php
if (isset( $_POST['dp_picsize'] ))
{
$dp_download_folder = $_POST['dp_picsize'];
}
?>
<!-- download_folder_form -->
<div id="dp_select_download">
<form id="select_download_folder" method="post" name="dp_download_directory" action="<?php echo $_SERVER['PHP_SELF']; ?>?image_id={image_id}">
<select name="dp_picsize" onchange="if (this. options[this. selectedIndex]. value != 0){ forms['jumpbox']. submit() }" class="dp_picsize_select">
<option value="/med">Bildgröße wählen</option>
<option value="/med">----------------</option>
<option value="/med">800 Pixel</option>
<option value="/download">Originalgröße</option>
</select>
<input type="image" src="{template_url}/images/hintergrund_submit_suche. gif" name="dp_download" id="submitbutton" />
</form>
</div>
<!-- END download_folder_form -->
(. . . )
Selecting "800 Pixel" in the form will set $dp_download_folder to "/med" (I checked this with echo $dp_download_folder), but this variable is still local and not identical with global $dp_download_folder, wich still has no value.
[EDIT by V@no]
I didn't change anything, just hit save button. For some reason the forum doesn't display properly php code until I save it...