On this code $appendPath was created for myFieldName['filename']
How would I add $appendimagePath to this code for myFieldName['visual'] ?

    $result = mysql_query($sql);
    //print $sql;
    if($result){
        $line = mysql_fetch_assoc($result);
        $myFile = $line[$myFieldName['filename']];
        if(file_exists($myFile)){
            pushfile($myFile, $action);
        } else {
            echo ("&retval=error 1 : file doesn't exist"."  ".$_REQUEST['theID']);
        }
    } else {
        echo "&retval=error 2 : No results from query!";
    }
    exit;


} else {


    $count=0;
    $sendback = "";
    $AmyDataSetup = array();
    $AqueryValues = explode("|", $queryValue);
    for($i=0;$i<sizeof($AqueryValues);$i++){
        $query = "SELECT * FROM ".$table_files." WHERE file like '%.mp3' ";
        $result = mysql_query($query);
        if($result){
            while ($line = mysql_fetch_assoc($result)) {
                $lineClean = array();
                foreach($line as $key=>$value){
                    if($count==0){
                        array_push($AmyDataSetup, $key);
                    }
                    if($key == $myFieldName['filename']){
                        if($forceTrailingSlash){
                            $myFile = forceTrailingSlash($appendPath).$value;
                        } else {
                            $myFile = @$appendPath.$value;
                        }
                        if(@$appendField != ''){
                            if($forceTrailingSlash){
                                $myFile = forceTrailingSlash(@$line[@$appendField]).$value;
                            } else {
                                $myFile = @$line[@$appendField].$value;
                            }

                        }
                        $lineClean[] = rawurlencode($myFile);
                    } else {
                        $lineClean[] = rawurlencode($value);
                    }
                }
                $sendback .= "&item$count=".implode("|", $lineClean);
                $count++;
            }
        }
    }

    $myDataSetup = implode("|", $AmyDataSetup);
    @mysql_free_result($result);
    mysql_close($link);
    $sendback .= "&totalitems=$count";
    $sendback .= "&datasetup=$myDataSetup";
    $sendback .= "&my_filename=".$myFieldName['filename'];
    $sendback .= "&my_artist=".$myFieldName['artist'];
    $sendback .= "&my_title=".$myFieldName['title'];
    $sendback .= "&my_visual=".$myFieldName['visual'];
    $sendback .= "&my_link=".$myFieldName['link'];
    $sendback .= "&my_id=".$myFieldName['uniqueID'];
    print ("$sendback");
}

?>

Edited 3 Years Ago by mike_2000_17: Fixed formatting

Do you mean how can you concatenate $appendimagePath with myFieldName ? $visualpath = $appendimagepath.myFieldName['visual']; like that ?

Do you mean how can you concatenate $appendimagePath with myFieldName['visual']?
$visualpath = $appendimagepath.myFieldName['visual']; like that?

Thank you for responding! I was was trying concatenate but not how you did. If you take a section of the code which is

for($i=0;$i<sizeof($AqueryValues);$i++){
    $query = "SELECT * FROM ".$table_files." WHERE file like '%.mp3' ";
    $result = mysql_query($query);
    if($result){
        while ($line = mysql_fetch_assoc($result)) {
            $lineClean = array();
            foreach($line as $key=>$value){
                if($count==0){
                    array_push($AmyDataSetup, $key);
                }
                if($key == $myFieldName['filename']){
                    if($forceTrailingSlash){
                        $myFile = forceTrailingSlash($appendPath).$value;
                    } else {
                        $myFile = @$appendPath.$value;
                    }
                    if(@$appendField != ''){
                        if($forceTrailingSlash){
                            $myFile = forceTrailingSlash(@$line[@$appendField]).$value;
                        } else {
                            $myFile = @$line[@$appendField].$value;
                        }

                    }
                    $lineClean[] = rawurlencode($myFile);
                } else {
                    $lineClean[] = rawurlencode($value);
                }
            }
            $sendback .= "&item$count=".implode("|", $lineClean);
            $count++;

what the code is doing is if a url is provided to appendPath, it added it to myFieldName['filename'] so for example when it retive the file name "music.mp3" If appendPath is provided with http://example.com then it will return as http://example.com/music.mp3.

Now my question is that what is done for myFieldName['filename'], how will i do the same for myFieldName['visual'] if I provide a url for appendimagePath?

PLEASE CHECK ATTACHMENT FOR THE TWO FILES. YOU WILL UNDERSTAND EVEN BETTER

Edited 3 Years Ago by mike_2000_17: Fixed formatting

Attachments
<?php


/////////////////////////////////////////////////////////////////
//                                                             //
//                     DATABASE SETUP:                         //
//                                                             //
/////////////////////////////////////////////////////////////////

$host        = "localhost";
$db          = "wimpy";
$publicUser  = "root";
$publicPwd   = "hackme";
$table_files = "mp3s";



/////////////////////////////////////////////////////////////////
//                                                             //
//                     RELATIONSHIPS:                          //
//                                                             //
/////////////////////////////////////////////////////////////////

$myField_ID		= 'id';
$myField_File	= 'filepath';
$myField_Artist	= 'artist';
$myField_Title	= 'title';
$myField_Image	= 'visual';
$myField_Link	= 'comments';

$sortField = $myField_Title;
$sortOrder = "DESC";
//$sortOrder = "ASC";

/////////////////////////////////////////////////////////////////
//                                                             //
//                         OTHER:                              //
//                                                             //
/////////////////////////////////////////////////////////////////

// Use a trailing slash/
$appendPath = '';
$appendField = '';
$forceTrailingSlash = FALSE;

?>
<?php
require_once("wimpy.sql.ed.configs.php");

// @clearstatcache();
// @ob_flush();

// connect to DB
$link = @mysql_connect($host, $publicUser, $publicPwd) 
	 or die("Check settings in mywimpy.configs.php and try again.");
mysql_select_db($db) 
	 or die(mysql_error());

/////////////////////////////////////////////////////////////////
//                                                             //
//                     COMMON FUNCTIONS:                       //
//                                                             //
/////////////////////////////////////////////////////////////////

function myStringPrep($value){
	if (get_magic_quotes_gpc()) {
		$value = stripslashes($value);
	}
	if(@version_compare(phpversion(),"4.3.0")=="-1") {
		$string = mysql_escape_string($value);
	} else {
		$string = mysql_real_escape_string($value);
	}
	$value = $string;
	return $value;
}



function striphack($string){
	$retval = $string;
	$retval = strip_tags(stripslashes($retval));
	$retval = strip_tags($retval);
	$retval = str_replace("\n", "x", $retval);
	$retval = str_replace("\r", "x", $retval);
	$retval = str_replace("\t", "x", $retval);
	$retval = str_replace("\\", "x", $retval);
	$retval = ereg_replace("\.+/", "x", $retval); 
	$retval = ereg_replace("\.\.","x",$retval); 
	//$retval = ereg_replace("^[\/]+", "x", $retval);
	return $retval;
}


function secureArray($array_in){	
	if(@is_array($array_in)){
		foreach ($array_in as $key => $value){
			$Atemp[striphack(urldecode($key))] = striphack($value);
		}
	} else {
		$Atemp = $array_in;
	}
	return $array_in;
}


function forceTrailingSlash($thePath){
	if($thePath == ''){
		return $thePath;
	} else {
		$lastChar = substr($thePath, strlen($thePath)-1, 1);
		if($lastChar == "/"){
			return $thePath;
		} else {
			if(strrpos($thePath, "\\")){
				return $thePath."\\";
			} else {
				return $thePath."/";
			}
		}
	}
}


if ( get_magic_quotes_gpc () ){
   function traverse ( &$arr ){
       if ( !is_array ( $arr ) ){
           return;
	   }
       foreach ( $arr as $key => $val ){
           is_array ( $arr[$key] ) ? traverse ( $arr[$key] ) : ( $arr[$key] = stripslashes ( $arr[$key] ) );
	   }
   }
   $gpc = array ( &$_GET, &$_POST, &$_COOKIE, &$_REQUEST);
   traverse ( $gpc );
}


$AcheckRequests = array(
						"queryWhere",
						"queryWhereCol",
						"queryWhereVal",
						"querySelect",
						"queryTable",
						"queryValue", 
						"action"
						);


$_REQUEST = secureArray($_REQUEST);
$_GET = secureArray($_GET);
$_POST = secureArray($_POST);


for($i=0;$i<sizeof($AcheckRequests);$i++){
	$var = $AcheckRequests[$i];
	if(!isset($_REQUEST[$var])){
		if(!isset($$var)){
			$$var = "";
		}
	} else {
		$$var = $_REQUEST[$var];
	}
}

function pushfile($filename, $kind){
	header("Pragma: public");
	header("Expires: Thu, 19 Nov 1981 08:52:00 GMT");
	header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
	header("Cache-Control: no-store, no-cache, must-revalidate");
	header("Content-Type: audio/x-mpeg, audio/x-mpeg-3, audio/mpeg3");
	if($kind == "downloadfile"){
		header("Cache-Control: private");
		header('Content-Disposition: attachment; filename="'.$Afile_info['basename'].'"' );
	}
	header("Content-Transfer-Encoding: binary");
	header("Content-Length: ".filesize($filename));
	$chunksize = 1*(1024*1024);
	$buffer = '';
	$cnt =0;
	$handle = fopen($filename, 'rb');
	if ($handle === false) {
		return false;
	}
	while (!feof($handle)) {
		$buffer = fread($handle, $chunksize);
		echo $buffer;
	}
	$status = fclose($handle);
	return $status;
}


$myFieldName['uniqueID'] = @$myField_ID;
$myFieldName['filename'] = @$myField_File;
$myFieldName['artist']   = @$myField_Artist;
$myFieldName['title']    = @$myField_Title;
$myFieldName['visual']   = @$myField_Image;
$myFieldName['link']     = @$myField_Link;


//////////////////////////////////////////////////
//                                              //
//             REQUEST HANDLING                 //
//                                              //
//////////////////////////////////////////////////

if($action=="serveMP3" || $action=="downloadfile"){

	
	$sql = "SELECT * FROM ".$table_files." WHERE ".$myFieldName['uniqueID']."='".myStringPrep($_REQUEST['theID'])."';";

	// HINT: Place a single / in front of /* to uncomment this section:
	/*
	print ($sql);
	exit;
	//*/


	// Both "theFile" and "theID" are returned from Wimpy. 
	// "theID" is prefered since this minimizes issues with 
	// weirdo characters such as: '&?"!@$#%$ and so on.
	//
	// If you are having difficulties, try uncommenting the line 
	// below, which uses the filename field to serve the file.

	//$sql = "SELECT * FROM ".$table_files." WHERE ".$myFieldName['filename']."='".myStringPrep($_REQUEST['theFile'])."';";

	$result = mysql_query($sql);
	//print $sql;
	if($result){
		$line = mysql_fetch_assoc($result);
		$myFile = $line[$myFieldName['filename']];
		if(file_exists($myFile)){
			pushfile($myFile, $action);
		} else {
			echo ("&retval=error 1 : file doesn't exist"."  ".$_REQUEST['theID']);
		}
	} else {
		echo "&retval=error 2 : No results from query!";
	}
	exit;


} else {

	
	$count=0;
	$sendback = "";
	$AmyDataSetup = array();
	$AqueryValues = explode("|", $queryValue);
	for($i=0;$i<sizeof($AqueryValues);$i++){
		$query = "SELECT * FROM ".$table_files." WHERE ".myStringPrep($queryWhere)."='".myStringPrep($AqueryValues[$i])."';";
		$result = mysql_query($query);
		if($result){
			while ($line = mysql_fetch_assoc($result)) {
				$lineClean = array();
				foreach($line as $key=>$value){
					if($count==0){
						array_push($AmyDataSetup, $key);
					}
					if($key == $myFieldName['filename']){
						if($forceTrailingSlash){
							$myFile = forceTrailingSlash($appendPath).$value;
						} else {
							$myFile = @$appendPath.$value;
						}
						if(@$appendField != ''){
							if($forceTrailingSlash){
								$myFile = forceTrailingSlash(@$line[@$appendField]).$value;
							} else {
								$myFile = @$line[@$appendField].$value;
							}
							
						}
						$lineClean[] = rawurlencode($myFile);
					} else {
						$lineClean[] = rawurlencode($value);
					}
				}
				$sendback .= "&item$count=".implode("|", $lineClean);
				$count++;
			}
		}
	}
	$myDataSetup = implode("|", $AmyDataSetup);
	@mysql_free_result($result);
	mysql_close($link);
	$sendback .= "&totalitems=$count";
	$sendback .= "&datasetup=$myDataSetup";
	$sendback .= "&my_filename=".$myFieldName['filename'];
	$sendback .= "&my_artist=".$myFieldName['artist'];
	$sendback .= "&my_title=".$myFieldName['title'];
	$sendback .= "&my_visual=".$myFieldName['visual'];
	$sendback .= "&my_link=".$myFieldName['link'];
	$sendback .= "&my_id=".$myFieldName['uniqueID'];
	print ("$sendback");
}


?>

You mean appendPath will have the value http://example.com and the filename is music.mp3 and you want to append those 2 ? $path=$appendPath."/".$filename; If that's not what you want, could you explain your question a lil better?

You mean appendPath will have the value http://example.com and the filename is music.mp3 and you want to append those 2 ? $path=$appendPath."/".$filename; If that's not what you want, could you explain your question a lil better?

Thank you every much for you help! Can you please take a look at the two files I uploaded. If you look at file wimpy.sql.ed.configs.php you will see $appendPath. Now if you look at wimpy.sql.ed.php you will see $appendPath is meant for $myField_File or $myFieldName. Now how would I add $appendimagePath meant for $myField_Image or $myFieldName

Remember that in the script (wimpy.sql.ed.configs.php)

$myFieldName = @$myField_File;
$myFieldName = @$myField_Image;

but basically I want to add $appendimagePath where I can put a url like I can for $appendPath

This article has been dead for over six months. Start a new discussion instead.