Jump to content

hellonoko

Members
  • Posts

    213
  • Joined

  • Last visited

Everything posted by hellonoko

  1. I have a simple query that updates a field by 1 every time a user upload a file. mysql_query("UPDATE users SET uploads = uploads +1 WHERE login = '$user'"); When I run this query in myPhpAdmin replacing $user with a user name it works correctly. However when I use it in the script it does not work. The $user variable is used early and is working. Full code below. <?php session_start(); error_reporting(E_ALL); ini_set('display_errors', '1'); //////////////////////////////////////////////// /////////////////////////////////////////////// $username = "sharingi_music"; $password = "music"; $hostname = "localhost"; $db_connect = mysql_connect( $hostname , $username, $password) or die ("Unable to connect to database"); mysql_select_db( "sharingi_music" , $db_connect); ///////////////////////////////////////////////// //////////////////////////////////////////////// //include '../menu.php'; echo "<br>"; $user = $_SESSION['login']; // // echo "<title>Share it!</title>"; echo '<table width="100%" align="center" border="0">'; echo "<tr>"; echo '<td bgcolor="#FFFFFF">'; echo '<font face="Arial" color="red" size="36">SHARING </font>'; echo "</td>"; echo "</tr>"; echo "</table>"; //copies all files uploaded into the users personal folder. if ($handle = opendir("/home2/sharingi/public_html/subdomains/$user/tmp/")) { //list all files and copies to users folder. while (false !== ($file = readdir ($handle))) { if ($file !== '.' && $file !== '..' && $file !== '.s' ) { //CLEAN UP FILE NAME $clean_name = str_replace( " ", "_" , $file); $hiddenname = date('Y-m-d') . "-" . rand( 1000,5000) . ".data"; /////////////////////////////////////////////////////// mysql_query("INSERT INTO songs ( SONG , USER, HIDDENNAME) VALUES ( '$clean_name' , '$user' , '$hiddenname' )"); /////////////////////////////////////////////////////// copy ("/home2/sharingi/public_html/subdomains/$user/tmp/$file" , "/home2/sharingi/public_html/subdomains/$user/filez/$hiddenname"); } } closedir ($handle); } /////////////////////////////////// mysql_close ( $db_connect); //////////////////////////////////// //////////////////////////////////// #Adds to the count of how many files the user had uploaded //////////////////////////////////// //////////////////////////////////// $db_connect = mysql_connect( $hostname , $username, $password) or die ("Unable to connect to database"); mysql_select_db( "sharingi_simpleauth" , $db_connect); //////////////////////////////////// //copies all files uploaded into the users personal folder. if ($handle = opendir("/home2/sharingi/public_html/subdomains/$user/tmp/")) { //list all files and copies to users folder. while (false !== ($file = readdir ($handle))) { if ($file !== '.' && $file !== '..' && $file !== '.s' ) { mysql_query("UPDATE users SET uploads = uploads +1 WHERE login = '$user'"); } } closedir ($handle); } /////////////////////////////////// mysql_close ( $db_connect); //////////////////////////////////// if ($handle = opendir("/home2/sharingi/public_html/subdomains/$user/tmp/")) { //echo "<b>Copying to master directory...<b><br>"; while (false !== ($file = readdir ($handle))) { if ($file !== '.' && $file !== '..' && $file !== '.s' ) { // CLEAN UP FILE NAME $clean_name = str_replace( " ", "_" , $file); //echo "$clean_name<br>"; copy ("/home2/sharingi/public_html/subdomains/$user/tmp/$file" , "/home2/sharingi/public_html/REPOSITORY/$hiddenname"); } } closedir ($handle); } //echo "<b>Files copied...<b>"; //DELETES TEMP FILES if ($handle = opendir("/home2/sharingi/public_html/subdomains/$user/tmp/")) { while (false !== ($file = readdir ($handle))) { if ($file !== '.' && $file !== '..' && $file !== '.s' ) { unlink("/home2/sharingi/public_html/subdomains/$user/tmp/$file"); //echo "$file<br>"; //copy ("files/$file" , "/home2/sharingi/public_html/REPOSITORY/$file"); } } closedir ($handle); } echo '<head>'; echo '<meta HTTP-EQUIV="REFRESH" content="4; url=http://www.sharingizcaring.com/REPOSITORY/">'; echo '</head>'; ?>
  2. I have two files menu.php and index.php Menu is included at the top of index.php Both use $_GET['user']; menu.php uses it to simply display the name of the user whos files are being viewed. index.php uses it to sort the files. If I call something like menu.php?user=testuser It works fine. However when index.php?user=test user is called the functionality in menu.php echos blank while index.php works. I made two simple pages external to this that used the same idea. One was a include of the other and each printed out the get variable. It worked just fine. Any ideas why mine is not? Menu.php <html> <head> <link href="http://www..com/styles.css" rel="stylesheet" type="text/css" /> </head> <body> <?php echo '<table width="100%" align="center" border="0">'; echo "<tr>"; echo '<td bgcolor="#FFFFFF">'; echo "<span class=red_menu>Hello: ". $_SESSION['login'] ."</span>"; echo '<span class=black_menu><a href="http://www..com/flashupload2/">Upload</a></span>'; echo "<span class=black_menu> | </span>"; echo '<span class=black_menu><a href="http://www..com/REPOSITORY/">Download</a></span>'; echo "<span class=black_menu> | </span>"; echo '<span class=black_menu><a href="http://www..com/flashupload2/logout.php">Logout</a></span>'; echo "<span class=black_menu> Viewing uploads from: "; echo $_GET['user']; echo "</span>"; echo "</td>"; echo "</tr>"; echo "</table>"; ?> index.php <?php // logon script error_reporting( E_ALL); require_once("../flashupload2/config.php"); checkLoggedIn("yes"); //////////////////////////////////////////////// /////////////////////////////////////////////// $username = "sharingi_music"; $password = "music"; $hostname = "localhost"; $db_connect = mysql_connect( $hostname , $username, $password) or die ("Unable to connect to database"); mysql_select_db( "sharingi_music" , $db_connect); ///////////////////////////////////////////////// //////////////////////////////////////////////// include 'http://www..com/menu.php'; //displays how many uploads each user has so far //include '../count2.php'; $view_files = $_GET['user']; //echo $view_files; $arr = array(); if ($view_files == 'all' || $view_files == NULL) { foreach (glob("*.*") as $filename) { $arr[$filename] = filemtime($filename); //echo $filename . " was last modified on " . date('M d Y, h:i:m', filemtime($filename)) . "<br>"; } } else { foreach (glob("/home2/sharingi/public_html/subdomains/".$view_files."/filez/*.*") as $filename) { $arr[$filename] = filemtime($filename); //echo $filename . " was last modified on " . date('M d Y, h:i:m', filemtime($filename)) . "<br>"; } } /// //asort($arr); //echo "<br>"; //foreach($arr as $key => $value) //{ // echo "$key was last modified on " . date('M d Y, h:i:m', $value) . "<br>"; //} /// arsort($arr); $olddate = 0; $date = 0; echo '<table width="100%" align="center" border="0">'; echo "<tr>"; echo '<td bgcolor="#FFFFFF">'; foreach($arr as $key => $value) { if ( $key !== "filelist3.php" && $key !== "index.php" ) { $date = date("d", filemtime($key)); $display_date = date ( "l F jS", filemtime($key)); if ( $date !== $olddate ) { $date_id = date ( "dmY", filemtime($key)); echo "<br><br>"; echo "<span class=date_font>$display_date</span><br>"; //echo "<span class=\"date_font\"><a href=\"#\" onClick=\"toggle_it('$date_id')\">".$display_date."</a></span><br>"; //echo "<br><br>"; } else { echo "<br>"; } $key = str_replace( "/home2/sharingi/public_html/subdomains/$view_files/filez/" , "" , $key); #print "<object type=\"application/x-shockwave-flash\" data=\"http://www..com/button/musicplayer.swf?&song_url=http://www..com/REPOSITORY/$key&b_colors=,,". player_color().",&\" width=\"17\" height=\"17\""; #print "<param name=\"movie\" value=\"http://www..com/button/musicplayer.swf?&song_url=http://www..com/REPOSITORY/$key&b_colors=,,".player_color().",&\"</object>"; echo "<a href=\"http://www..com/download.php?file=$key\"><img src=\"http://www..com/down.png\" alt=\"download\" width=\"16\" height=\"16\" border=\"0\" /></a>"; //print "<img src=\"noflash.gif\" width=\"17\" height=\"17\" alt=\"\" />"; //print "<span class=small_font><a href=\"http://www..com/REPOSITORY/$key\" class=".color().">"; echo "<span class=small_font><a href=\"javascript:popUp('http://www..com/player.php?p=".$key."')\" class=".color().">"; $result = mysql_query("SELECT SONG FROM songs WHERE HIDDENNAME = '$key'"); while ($row = mysql_fetch_row($result)) { echo " "; //echo "<a href=\"javascript:popUp('player.php?p=".$key."')\">".$row[0].""; echo $row[0]; } echo "</a></span>"; $date = date("d", filemtime($key)); /////////////////////////////////////////////////////// $result = mysql_query("SELECT USER FROM songs WHERE HIDDENNAME = '$key'"); while ($row = mysql_fetch_row($result)) { echo "<span class=small_font> - from: </span>"; echo "<span class=small_font_user>"; //echo $row[0]; echo "<a href=\"http://www..com/REPOSITORY/index.php?user=".$row[0]."\">".$row[0]."</a>"; echo "</span>"; } } $olddate = $date; } echo '</table>'; /////////////////////////////////// mysql_close ( $db_connect); //////////////////////////////////// echo "</td>"; echo "</tr>"; echo "</table>"; function color() { $color = rand( 1,7); if ($color == 1) { return "red"; } if ($color == 2) { return "green"; } if ($color == 3) { return "blue"; } if ($color == 4) { return "yellow"; } if ($color == 5) { return "babyblue"; } if ($color == 6) { return "purple"; } if ($color == 7) { return "grey"; } } function player_color() { $color = rand(1,7); if ($color == 1) { return "FF0000"; } if ($color == 2) { return "00FF00"; } if ($color == 3) { return "0000FF"; } if ($color == 4) { return "FFFF00"; } if ($color == 5) { return "00FFFF"; } if ($color == 6) { return "FF00FF"; } if ($color == 7) { return "999999"; } } ?> </body> </html>
  3. No luck. Full code below. <?php //////////////////////////////////////////////// /////////////////////////////////////////////// $username = "sharingi_music"; $password = "music"; $hostname = "localhost"; $db_connect = mysql_connect( $hostname , $username, $password) or die ("Unable to connect to database"); mysql_select_db( "sharingi_music" , $db_connect); ///////////////////////////////////////////////// //////////////////////////////////////////////// $file = "http://www..com/REPOSITORY/".$_GET['file'].""; $filename = $_GET['file']; $result = mysql_query("SELECT SONG FROM songs WHERE HIDDENNAME = '$filename'"); while ($row = mysql_fetch_row($result)) { $name = $row[0]; } #header('Content-Type: application/force-download'); #header('Content-Type: application/octet-stream'); #header('Content-Type: application/mp3'); //header('Content-Disposition: attachment; filename='.$name); #header('Content-Disposition: attachment; filename="' . $name . '"'); #readfile("$file"); #header("Pragma: public"); #header("Expires: 0"); #header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); #header("Content-Type: application/force-download"); #header("Content-Disposition: attachment; filename=".basename($name)); #header("Content-Description: File Transfer"); #@readfile($file); header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; filename="' . $name . '"'); readfile("$file"); ?>
  4. Works but also just instantly downloads without any Save As... dialog.
  5. You could do a series of forced downloads using header()
  6. Below is my code to download a file. header('Content-Type: application/force-download'); #header('Content-Type: application/octet-stream'); #header('Content-Type: application/mp3'); //header('Content-Disposition: attachment; filename='.$name); header('Content-Disposition: attachment; filename="' . $name . '"'); readfile("$file"); From what I have read this should force a Save As... dialog but it does not for some reason. I have tried this in FF3 Safari and Chrome. Does anyone know how I can force it to display a download dialog box?
  7. Haha no but pretty much. <html> <head> <link href="http://www..com/styles.css" rel="stylesheet" type="text/css" /> <script language="javascript"> function toggle_it(itemID){ // Toggle visibility between none and inline if ((document.getElementById(itemID).style.display == 'none')) { document.getElementById(itemID).style.display = 'inline'; } else { document.getElementById(itemID).style.display = 'none'; } } </script> </head> <body> <?php echo $_GET['user']; echo '<table width="100%" align="center" border="0">'; echo "<tr>"; echo '<td bgcolor="#FFFFFF">'; echo "<span class=red_menu>Hello: $_SESSION[login] </span>"; echo '<span class=black_menu><a href="http://www..com/flashupload2/">Upload</a></span>'; echo "<span class=black_menu> | </span>"; echo '<span class=black_menu><a href="http://www..com/REPOSITORY/">Download</a></span>'; echo "<span class=black_menu> | </span>"; echo '<span class=black_menu><a href="http://www..com/flashupload2/logout.php">Logout</a></span>'; echo "<span class=black_menu> Viewing uploads from: "; echo $display; echo "</span>"; echo "</td>"; echo "</tr>"; echo "</table>"; ?> Works when called on its own. Fails when used as an include of index.php and when I say fails i mean just echos empty.
  8. Yes that is what I am saying I do and DOES work. If I go to menu.php?user=bob it displays bob. If i go to index.php?user=bob it display nothing but does displays bobs files.
  9. I have a $_GET variable 'user' in the query string that I use am using to display a certain users files. index.php?user=bob I have two files: menu.php and index.php In the menu.php file I am trying to use $_GET['user']; to display a line that says: View files from [and the user name here] Then in index.php the same $_GET variable is used to choose what files are displayed. The index.php usage works and when I call menu.php on its own it works. But when I use menu.php as an include of index.php the $_GET variable will not work in menu.php Can I not use $_GET variables in include files?
  10. From what I have read my code below should force a save dialog in the browser. However it just causes a direct download. header('Content-Type: application/force-download'); header('Content-Type: application/octet-stream'); header('Content-Type: application/mp3'); //header('Content-Disposition: attachment; filename='.$name); header('Content-Disposition: attachment; filename="' . $name . '"'); readfile("$file");
  11. I am using the below code to download a file that is stored in a obfuscated matter as what it actually is when downloaded. header('Content-type: application/octet-stream'); header("Content-Disposition: attachment; filename="$name""); readfile("$file"); When I have the second line written as: header('Content-Disposition: attachment; filename="bigpicture.jpeg"'); It works fine. However when I try to change it around so that I can use $name which contains the actual name the file should be saved as the code does not work or simply downloads as download.php the name of the download script. How do I properly insert my $name variable? Thanks
  12. Maybe like.... SELECT * FROM downloads WHERE category = 'categorytheywanttoview' ?
  13. I dont know if it would be faster but you could use a glob. I don't know if it supports hard drives either.
  14. Just the session_start() function needs to be at the top of the page or the top of the first included page it has to be processed first. http://www.wallpaperama.com/forums/warning-session-start-function-session-start-cannot-send-session-t416.html <?php session_start(); ?> everything else
  15. You could put in a line at the top that checks to see if the file exists on the server. Then if it does exist don't run the rest of the script. But that might prevent over writing of the file which you might not like. Also add in lines after the upload part of the script that clean out the variables holding the upload info. And then a check at the beginning perhaps.
  16. Your session start has to come before anything at all in the page. so: <html> <?php session_start() will fail
  17. On my web site I am going to be storing files in a manner that makes them unrecognizable. For example: 9lj234lkj42l3kj.myextension or just: randomfilename.txt These names and their actual information will be stored in a data base as a reference to the file. When I display these files for download the actual link to the file will be something like http://www.mysite.com/files/lkj34hkj32432.txt but the link will display as Photo10.jpg as referenced from the database. So what I need to figure out how to do is make some kind of downloading script that changed the file name to the referenced name (Photo10.jpg) but only upon download.
  18. You could use the date() function or getDate() function to see if a certain date was a friday and then SELECT the 7 rows before that. Or he 7 rows ahead. Or all rows until the date equaled your current date + or - 7. Something like that?
  19. You could try wamp instead.
  20. Yup. Just before an admin did something on the server that fixed it. But now I have broken it again. Here is the code: <?php // logon script error_reporting( E_ALL); include_once("http://www.sharingizcaring.com/flashupload2/config.php"); checkLoggedIn("yes"); //////////////////////////////////////////////// /////////////////////////////////////////////// $username = "sharingi_music"; $password = "music"; $hostname = "localhost"; $db_connect = mysql_connect( $hostname , $username, $password) or die ("Unable to connect to database"); mysql_select_db( "sharingi_music" , $db_connect); ///////////////////////////////////////////////// //////////////////////////////////////////////// include 'http://www.sharingizcaring.com/menu.php'; //displays how many uploads each user has so far //include '../count2.php'; $view_files = $_GET['user']; echo $view_files; $arr = array(); foreach (glob("*.*") as $filename) { $arr[$filename] = filemtime($filename); //echo $filename . " was last modified on " . date('M d Y, h:i:m', filemtime($filename)) . "<br>"; } /// //asort($arr); //echo "<br>"; //foreach($arr as $key => $value) //{ // echo "$key was last modified on " . date('M d Y, h:i:m', $value) . "<br>"; //} /// arsort($arr); $olddate = 0; $date = 0; echo '<table width="100%" align="center" border="0">'; echo "<tr>"; echo '<td bgcolor="#FFFFFF">'; foreach($arr as $key => $value) { if ( $key !== "filelist3.php" && $key !== "index.php" ) { $date = date("d", filemtime($key)); $display_date = date ( "l F jS", filemtime($key)); if ( $date !== $olddate ) { $date_id = date ( "dmY", filemtime($key)); echo "<br><br>"; echo "<span class=date_font>$display_date</span><br>"; //echo "<span class=\"date_font\"><a href=\"#\" onClick=\"toggle_it('$date_id')\">".$display_date."</a></span><br>"; //echo "<br><br>"; } else { echo "<br>"; } print "<object type=\"application/x-shockwave-flash\" data=\"http://www.sharingizcaring.com/button/musicplayer.swf?&song_url=http://www.sharingizcaring.com/REPOSITORY/$key&b_colors=,,". player_color().",&\" width=\"17\" height=\"17\""; print "<param name=\"movie\" value=\"http://www.sharingizcaring.com/button/musicplayer.swf?&song_url=http://www.sharingizcaring.com/REPOSITORY/$key&b_colors=,,".player_color().",&\"</object>"; //print "<img src=\"noflash.gif\" width=\"17\" height=\"17\" alt=\"\" />"; print "<span class=small_font><a href=\"http://www.sharingizcaring.com/REPOSITORY/$key\" class=".color()."> $key</a></span>"; $date = date("d", filemtime($key)); /////////////////////////////////////////////////////// $result = mysql_query("SELECT USER FROM songs WHERE SONG = '$key'"); while ($row = mysql_fetch_row($result)) { echo "<span class=small_font> - from: </span>"; echo "<span class=small_font_user>".$row[0]."</span>"; } } $olddate = $date; } echo '</table>'; /////////////////////////////////// mysql_close ( $db_connect); //////////////////////////////////// echo "</td>"; echo "</tr>"; echo "</table>"; function color() { $color = rand( 1,7); if ($color == 1) { return "red"; } if ($color == 2) { return "green"; } if ($color == 3) { return "blue"; } if ($color == 4) { return "yellow"; } if ($color == 5) { return "babyblue"; } if ($color == 6) { return "purple"; } if ($color == 7) { return "grey"; } } function player_color() { $color = rand(1,7); if ($color == 1) { return "FF0000"; } if ($color == 2) { return "00FF00"; } if ($color == 3) { return "0000FF"; } if ($color == 4) { return "FFFF00"; } if ($color == 5) { return "00FFFF"; } if ($color == 6) { return "FF00FF"; } if ($color == 7) { return "999999"; } } ?> </body> </html>
  21. Are N/A vlues null? empty? What about something like. SELECT * FROM db WHERE tm >= '0' AND tm != NULL or when you display the values of tm if ( array[$value != empty) echo or whatever
  22. This is really strange now. It has broken again. I added in two lines $view_files = $_GET['user']; echo $view_files; And the error is back.
×
×
  • 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.