Jump to content

nickharambee

Members
  • Posts

    13
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

nickharambee's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Mmmh. I am not too clever with PHP (the script was written mostly by another). Would the allowed folder array just allow folders that have mp3s in? Because the folders that have MP3s in could be named anything (every user who logs in to the site gets a folder which is generated by their login), I couldn't include folders by name. The issue is that, because folders are generated on login, empty folders are getting added to the folder list array, and I only want them to show up once users have uploaded MP3 files to them.
  2. I have an allowed array too, which specifies filetypes, i.e. $allowedfiletypes=array('mp3'); but this still adds empty folders to the folder list that is generated. Here is the full script: <?php /* * ===================== * FUNctions * ===================== */ /* * array subvalue sort -- from: http://www.firsttube.com/read/sorting-a-multi-dimensional-array-with-php/ * * this function lets me sort the multidimensional array containing song/artist information by the file modified time, a subvalue */ function subval_sort($a,$subkey) { foreach($a as $k=>$v) { $b[$k] = strtolower($v[$subkey]); } arsort($b); //change this to 'asort' for ascending foreach($b as $key=>$val) { $c[] = $a[$key]; } return $c; } /* * function written to clean up my messy code (too many slashes ... display '/' as '&raquo' (>>) for user friendliness ) */ function clean($dirty, $type='general', $debug=false){ //debug if($debug==true) echo'<br />value before clean: '.$dirty.' (first character: '.substr($dirty, 0, 1).')'; /* * General cleaning -- remove '/' at front and end */ if(substr($dirty, 0, 1)=='/'){ //echo'<br />found leading /'; $dirty=substr($dirty, 1, strlen($dirty)-1); } if(substr($dirty, -1)=='/') $dirty=substr($dirty, 0, strlen($dirty)-1); //prepare the subfolder display information by type if($type=='link') $dirty=str_replace(array('//','»'), array('/', '/'), $dirty); else if($type=='display') $dirty=str_replace(array('///','//','/'), array('»','»', '»'), $dirty); else $dirty=str_replace('»', '/', $dirty); if($debug==true)echo' | after clean: '.$dirty; //return return $dirty; } function makelink($linkme, $debug=false){ $link=str_replace('»', '/', $linkme); $link=str_replace('//', '/', $link); return $link; } function recursiveGetSongs($directory, $fileinfo, $useID3, $getID3, $parent=null, $debug, $filtered=null){ /* * configure function here: * * _usage_ * > the disallowed array should include any folders or files you explicitely don't want displayed * > the allowedfiletypes array should include any file extentions you want to play */ $disallowed=array('..', '.', 'simon', 'steve'); $allowedfiletypes=array('mp3'); if($filtered!=null){ $disallowed=array_merge((array)$filtered, (array)$disallowed); } //simple error fix if($directory=='./') $directory='.'; //debug if ($debug==true)echo'Dir to open: '.$directory; //open directory $dir = opendir($directory); while ($read = readdir($dir)) { //if ( !in_array($read, $disallowed) AND ( $filter!=null AND in_array($read, $filter) ) ) if ( !in_array($read, $disallowed) ) { if($debug==true)echo $read.'<br />'; //if is not dir, handle file if ( !is_dir($directory.'/'.$read) ){ if($debug==true)echo '^^ not dir | dir: '.$directory.'<br />'; if( in_array(substr($read, -3, 3), $allowedfiletypes) ){ if($useID3==TRUE){ //store id3 info $FullFileName = realpath($directory.'/'.$read); if($debug==TRUE)echo'<br />FFN » '.$FullFileName; $ThisFileInfo = $getID3->analyze($FullFileName); getid3_lib::CopyTagsToComments($ThisFileInfo); $fileinfo[$read]['artist']=$ThisFileInfo['comments_html']['artist'][0]; $fileinfo[$read]['title']=$ThisFileInfo['comments_html']['title'][0]; $fileinfo[$read]['album']=$ThisFileInfo['comments_html']['album'][0]; $fileinfo[$read]['filename']=$ThisFileInfo['filename']; $fileinfo[$read]['modified']=date ("YmdHis", filemtime($directory.'/'.$read)); if($debug==true) echo "<br />$read was last modified: " . date ("YmdHis", filemtime($directory.'/'.$read)); $fileinfo[$read]['path']=$directory.'/'.$read; if($debug==true)echo'<span style="margin-left: 10px;">path:'.$fileinfo[$read]['path'].' > fn: '.$fileinfo[$read]['filename'].'</span><br /><br />'; if($parent!=null) $fileinfo[$read]['from']=str_replace(array('./', '//', '/'), array('', '»', '»'), $directory); // was =$parent else $fileinfo[$read]['from']='root'; //testing this if($debug==true)echo'<br />'.$fileinfo[$read]['from'].'<br />'; //debug //echo$ThisFileInfo['filename'].'<br />'; } else{ //store filename $fileinfo[$fileinfo['count']]['path']=$directory.'/'.$read; $fileinfo[$fileinfo['count']]['fn']=$read; if($parent!=null) $fileinfo[$fileinfo['count']]['from']=str_replace(array('./', '//', '/'), array('', '»', '»'), $directory); $fileinfo[$fileinfo['count']]['modified']=date ("YmdHis", filemtime($directory.'/'.$read)); //$fileinfo[$fileinfo['count']]=date ("YmdHis", filemtime($directory.'/'.$read)); } //inc counter $fileinfo['count']=$fileinfo['count']+1; // had ++ and it didn't work } else ;//do nothing } //else, must be a folder (as determined above), recurse folder else{ //debug if($debug==true)echo '^^ DIR<br />'; //capture subfolders in case they are needed if($parent!='')$fileinfo['folders'].=$parent.'»'.$read.'|'; else $fileinfo['folders'].=$read.'|'; $fileinfo['folderpaths'].=$directory.'/|'; $fileinfo=recursiveGetSongs($directory.'/'.$read, $fileinfo, $useID3, $getID3, $parent.'/'.$read, $debug, $filtered); } } } closedir($dir); return $fileinfo; } ?>
  3. Hi, I am using an array which allows me to prevent particular subfolders from being included in a script that generates an audio playlist. It looks like this: $disallowed=array('..', '.', 'simon', 'steve'); I would like to find a way of disallowing any folders which are empty, or, perhaps, better still, disallowing folders that do not have any MP3s in them (in case the script interprets folders as not empty if they contain system files which are automatically generated). Would someone be able to help with this? Thanks, Nick
  4. Hi, I am trying to make some adjustments to uploadify.php which comes with the latest version of uploadify (3.0 beta), so that it works with a session variable that stores the login username and adds it to the path for uploads. Here is uploadify.php as it currently looks: <?php session_name("MyLogin"); session_start(); $targetFolder = '/songs/' . $_SESSION['name']; // Relative to the root if (!empty($_FILES)) { $tempFile = $_FILES['Filedata']['tmp_name']; $targetPath = $_SERVER['DOCUMENT_ROOT'] . $targetFolder; $targetFile = rtrim($targetPath,'/') .'/'. $_FILES['Filedata']['name']; // Validate the file type $fileTypes = array('m4a','mp3','flac','ogg'); // File extensions $fileParts = pathinfo($_FILES['Filedata']['name']); if (in_array($fileParts['extension'],$fileTypes)) { move_uploaded_file($tempFile,$targetFile); echo '1'; } else { echo 'Invalid file type.'; } } echo $targetFolder; ?> I added echo $targetFolder; at the bottom so that I could make sure that the string returned was correct, and it is, i.e. '/songs/nick'. For some reason though, uploads are not going to the correct folder, i.e. the username folder, but instead are going to the parent folder 'songs'. The folder for username exists, with correct permissions, and when I manually enter $targetFolder = '/songs/nick'; all works fine. Which strikes me as rather strange. I have limited experience of using php, but wonder how if the correct string is returned by the session variable, the upload works differently than with the manually entered string. Any help would be much appreciated. It's the last issue with a website that was due to go live 2 days ago! Thanks, Nick
  5. I now have the session variable available to the uploadify.php page, by adding session_name("MyLogin"); above session_start(); Now when I add echo $targetFolder; it returns the correct path: '/songs/nick', but the uploads are still going to the parent directory 'songs'. When I manually enter $targetFolder = '/songs/nick'; all works fine. Which seems rather weird. Does anyone have any ideas as to what might be going on? Thanks, Nick
  6. Thanks, Here is the full script, as that should help to show what is included when: <?php $targetFolder = '/songs/'; // Relative to the root if (!empty($_FILES)) { $tempFile = $_FILES['Filedata']['tmp_name']; $targetPath = $_SERVER['DOCUMENT_ROOT'] . $targetFolder; $targetFile = rtrim($targetPath,'/') .'/'. $_FILES['Filedata']['name']; // Validate the file type $fileTypes = array('m4a','mp3','flac','ogg'); // File extensions $fileParts = pathinfo($_FILES['Filedata']['name']); if (in_array($fileParts['extension'],$fileTypes)) { move_uploaded_file($tempFile,$targetFile); echo '1'; } else { echo 'Invalid file type.'; } } ?> The only other php file included with the script contains this: <?php if (file_exists($_SERVER['DOCUMENT_ROOT'] . '/uploads/' . $_POST['filename'])) { echo 1; } else { echo 0; } ?> I somehow need to include the '/songs/' part as well as that doesn't vary, only the subfolders in 'songs'
  7. Hi, I am pretty much a new newbie when it comes to PHP, and have a problem that I need to solve, for a website that has to go live tomorrow. Basically I have been using a javascript upload script called 'uploadify' which had an option for the upload folder which was added to the script in the form: 'folder' : '/songs/<?php echo $_SESSION["name"];?>', I added the php echo to return the username from a PHP login, so it gets added to the path to the upload folder (each user has their own subfolder for uploading to). With the new version of the uploadify script, the folder option has been moved to a separate PHP file where it is now in the form: $targetFolder = '/songs/'; I need to find a way of adding the username variable to this line. I have tried using echo in various ways, and googled about, but it has stumped me, simple as it may be. If anyone could let me know how I construct this line I'd be very grateful. Time is of the essence, as they say... Thanks, Nick
  8. Hi, I have limited experience of using PHP, but having done some searching around it would seem that it is possible to convert audio files that are uploaded through a web page to mp3 using ffmpeg. The audio files would be uploaded using the Uploadify script to subfolders that are named according to the user's login. I would need the PHP script to be able to process all audio files that are either not in MP3 format, or are in MP3 format but greater than 192kbps, deleting the original file after the conversion. Am I right in thinking that this could be achieved using PHP, and if so, can anyone get me started with some code, or a link to a webpage with some code? Also, I am currently using Hostpapa for hosting my website, and I understand that they don't include ffmpeg, and also don't allow ssh. I read on one website that I could still install a compiled version of ffmpeg on a shared server, but I am not sure if this means that it would work on Hostpapa, or whether I would need to change my host to get ffmpeg working. Any advice on any of this would be welcome! Thanks, Nick
  9. The login code is the same as the code above, i.e. log.php and login.php
  10. just to say that I now have a new upload script that does not conflict with the php login I posted above, but with Pikachu2000 suggesting that the script is outdated and "generally rather poor", I would be grateful for any advice in either updating it, or looking elsewhere for a better php login script. thanks nick
  11. OK, here's the code for the log.php <? session_name("MyLogin"); session_start(); if($_GET['action'] == "login") { $conn = mysql_connect("localhost","user","password"); // your MySQL connection data $db = mysql_select_db("DATABASENAME"); //put your database name in here $name = $_POST['user']; $q_user = mysql_query("SELECT * FROM USERS WHERE login='$name'"); if(mysql_num_rows($q_user) == 1) { $query = mysql_query("SELECT * FROM USERS WHERE login='$name'"); $data = mysql_fetch_array($query); if($_POST['pwd'] == $data['password']) { session_register("name"); header("Location: yourpage.php"); // success page. put the URL you want exit; } else { header("Location: login.php?login=failed&cause=".urlencode('Wrong Password')); exit; } } else { header("Location: login.php?login=failed&cause=".urlencode('Invalid User')); exit; } } // if the session is not registered if(session_is_registered("name") == false) { header("Location: login.php"); } ?> And here's the code for the login.php: <? session_name("MyLogin"); session_start(); session_destroy(); if($_GET['login'] == "failed") { print $_GET['cause']; } ?> <form name="login_form" method="post" action="log.php?action=login"> Login: <input type="text" name="user"><BR> Password: <input type="password" name="pwd"><BR> <input type="submit"> </form> And here's the code for the upload.php which I believe there is a conflict with: <?php /** * Styx::Upload - Handles file uploads * * @package Styx * @subpackage Utility * * @license MIT-style License * @author Christoph Pojer <christoph.pojer@gmail.com> */ class Upload { /** * Moves the uploaded file to the specified location. It throws a UploadException * if anything goes wrong except for if the upload does not exist. This can be checked with {@link Upload::exists()} * * @param string $file * @param string $to * @param array $options * @return bool|string Path to moved file or false if the specified upload does not exist */ public static function move($file, $to, $options = null){ if(!self::exists($file)) return false; $options = array_merge(array( 'name' => null, 'extension' => null, 'size' => null, 'chmod' => 0777, 'overwrite' => false, 'mimes' => array(), ), $options); $file = $_FILES[$file]; if($options['size'] && $file['size']>$options['size']) throw new UploadException('size'); $pathinfo = pathinfo($file['name']); if($options['extension']) $pathinfo['extension'] = $options['extension']; if(!$pathinfo['extension']) throw new UploadException('extension'); if(count($options['mimes'])){ $mime = self::mime($file['tmp_name'], array( 'default' => $file['type'], 'extension' => $pathinfo['extension'], )); if(!$mime || !in_array($mime, $options['mimes'])) throw new UploadException('extension'); } $file['ext'] = strtolower($pathinfo['extension']); $file['base'] = basename($pathinfo['basename'], '.'.$pathinfo['extension']); $real = realpath($to); if(!$real) throw new UploadException('path'); if(is_dir($real)) $to = $real.'/'.($options['name'] ? $options['name'] : $file['base']).'.'.$file['ext']; if(!$options['overwrite'] && file_exists($to)) throw new UploadException('exists'); if(!move_uploaded_file($file['tmp_name'], $to)) throw new UploadException(strtolower($_FILES[$file]['error']<=2 ? 'size' : ($_FILES[$file]['error']==3 ? 'partial' : 'nofile'))); chmod($to, $options['chmod']); return realpath($to); } /** * Returns whether the Upload exists or not * * @param string $file * @return bool */ public function exists($file){ return !(empty($_FILES[$file]['name']) || empty($_FILES[$file]['size'])); } /** * Returns (if possible) the mimetype of the given file * * @param string $file * @param array $options */ public function mime($file, $options = array()){ $file = realpath($file); $options = array_merge(array( 'default' => null, 'extension' => strtolower(pathinfo($file, PATHINFO_EXTENSION)), ), $options); $mime = null; $ini = error_reporting(0); if (function_exists('finfo_open') && $f = finfo_open(FILEINFO_MIME, getenv('MAGIC'))){ $mime = finfo_file($f, $file); finfo_close($f); } error_reporting($ini); if(!$mime && in_array($options['extension'], array('gif', 'jpg', 'jpeg', 'png'))){ $image = getimagesize($file); if(!empty($image['mime'])) $mime = $image['mime']; } if(!$mime && $options['default']) $mime = $options['default']; if((!$mime || $mime=='application/octet-stream') && $options['extension']){ static $mimes; if(!$mimes) $mimes = parse_ini_file(pathinfo(__FILE__, PATHINFO_DIRNAME).'/MimeTypes.ini'); if(!empty($mimes[$options['extension']])) return $mimes[$options['extension']]; } return $mime; } } class UploadException extends Exception {}
  12. Thanks. Like I said, I'm a PHP newbie. Basically I'm just looking for a customised login page. Could you recommend a more secure script/method?
  13. Hi, I am a php newbie, who has a page that relies on some php scripts, and to which I am trying to add a login page written in php. I took the example from here: http://www.howtodothings.com/computers-internet/how-to-make-a-login-system-for-your-website Basically it consists of adding: <? require("log.php"); ?> to the top of any page I want to protect, a log.php file which performs the actions of the form, linking to a mySQL database, and a login.php file which contains the form. I have the login working fine, but it breaks one of the PHP scripts on the page that is protected. It is an upload script, called Weaverbox, based on FancyUpload. The uploads which are handled by a file called upload.php, aren't happening. The progress shows that they are being uploaded, but nothing is uploaded, and there is no success message. As soon as I remove the code from the top of the page requiring log.php all works fine again. I think I may have to add some rules/extensions to resolve this conflict, but I don't know how to go about this. Would someone be able to help me get it sorted? Thanks Nick
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.