Jump to content

ibanez270dx

Members
  • Posts

    53
  • Joined

  • Last visited

    Never

Posts posted by ibanez270dx

  1. Hi everyone,

      It's been awhile since I've coded in PHP and I can't figure out whats wrong with my code... I have a simple function to grab a field from my database and return it. I can make it work without the function, but when I implement it as a function, it breaks - no error, just a blank page.

     

    This works fine:

    $page = "page_about";
    $sql = "SELECT body FROM " . $page . " WHERE id=1";
    $result = @mysql_query($sql,$connection) or die(mysql_error());
    $row = mysql_fetch_array($result);
    $display = $row[0];
    

    But this does not:

    function grabBody($page)
    {
    $sql = "SELECT body FROM " . $page . " WHERE id=1";
    $result = @mysql_query($sql,$connection) or die(mysql_error());
    $row = mysql_fetch_array($result);
    return $row[0];
    }
    $display = grabBody("page_about");
    

     

    If anyone has any idea whats wrong, please let me know!!

     

    Thank you,

      - Jeff Miller

  2. Hello,

    I have an application written in PHP that is used to securely share files, etc... however, I would like to prompt a download box when a user clicks to download a file. Currently, if the file is an accepted MIME type like .xls, .csv, .jpg, .gif, etc... it just opens the file in the browser or in the appropriate application. Is there a way I can force a download prompt?

     

    Thanks,

    - Jeff

  3. Hello,

    I've got a PHP app that I'd like to use hash mapping in. I haven't seen this kind of functionality in PHP before, so I was wondering if this is possible. What I'd like to do is this equilvilant to this in Ruby:

     

    myhashmap = {}
    myhashmap['person1'] = ['John','Smith','555-555-5555']
    myhashmap['person2'] = ['John','Doe','444-444-4444']
    

     

    Does anybody know if PHP has something similar?

     

    Thanks,

    - Jeff

  4. I just tried using an fopen type thing - it reads that it's up when the server is up, but when it's down, it just times out.

     

    Perhaps a better way to go about this is to check if my WEBrick service is running on port 4243? Is that possible?

  5. Hello,

    I have a PHP page that basically just takes some user input (dates) and puts them into a URL which points to a WEBrick server and initializes some Ruby scripts. Everything works perfectly fine, with one exception. I want to ensure that when my WEBrick server gets kicked or is down for some reason, that PHP can realize it and act accordingly. I tried some basic PHP exception handling, but to no avail. What I have is this:

     

           try
            {
             echo "<META http-equiv=\"refresh\" content=\"0;URL=http://harrier:4243/cpa?from=$_POST[FromDate]&to=$_POST[ToDate]\">";
             exit;
            }
            catch(Exception $e)
            {
             echo 'Message: ' .$e->getMessage();
            }
    

     

    ...which leaves me with a 404 if my WEBrick server is down. Thus, I suppose I need PHP to "touch" and ensure the WEBrick server is alive before executing the META refresh tag. Can this be done? If so, how?

     

    Any and all help is appreciated!

     

    Thanks,

    - Jeff

  6. Hello everyone,

    I have a code snippet that parses a CSV file... it works fine on my personal server (Apache, PHP 4.3), but I recently installed a fresh copy of PHP 5.2.5 on a virtual server here at work and it doesn't seem to want to do it... I'm running PHP 5.2.5 on IIS v6 w/ ISAPI. I know PHP is working correctly because my test page works fine. It will not display the results in <? echo "$display" ?>. However, it will echo out when it is still in the PHP tags. It is something like this:

     

    $row = 1;
    $handle = fopen("test.csv", "r");
    while (($data = fgetcsv($handle, 1500, ",")) !== FALSE) 
       {
        if($row==1)
    {
             $row++;
             continue;
            }
        $num = count($data);
    
        $display .= "<tr><td><font size=2 face=arial>$data[0]</td>
     	        blah blah blah
    	        <td><font size=2 face=arial>$data[41]</td></tr>";
          
       }
    
    fclose($handle);
    
    echo $display;     // THIS WORKS
    ?>
    
    <? echo "$display" ?> // THIS DOESN'T WORK
    
    

     

    Any help is appreciated!

     

    Thanks,

    - Jeff

  7. Hello,

    This is probably a really simple problem, but I have a PHP page that parses a CSV file and puts it into an array, etc... Anyhow, I would like the CSV to be parsed from line 2 on, omitting line 1. My code looks like this:

     

    $handle = fopen("test.csv", "r");
    while (($data = fgetcsv($handle, 1500, ",")) !== FALSE) 
       {
        $num = count($data);
    
        $display .= "<tr><td>$data[0]</td><td>$data[1]</td><td>$data[2]</td><td>$data[3]</td><td>$data[4]</td></tr>";
          
       }
    fclose($handle);
    

     

    Thanks for you help!

    - Jeff

  8. Hi,

    I'm running PHP on a remote server and I can't seem to get this line to actually work:

     

    <a href="index2.php?typeorder=fi_tripnum">

     

    Whereas I want to pickup that $typeorder = "fi_tripnum";

     

    However, it doesn't get picked up by index2.php (The page that the hyperlink is on is index2.php - the same page it wishes to send to). I checked PHP.ini and REGISTER_GLOBALS is on. Is there anything else that I should check?

     

    Thanks,

    - Jeff

  9. Hey, thanks for you input. The array("audio/mpeg"); seems to work fine - I'm not too worried about security right now though, this is just a small DB app for a small group of people. Anyway, I'm still having trouble with large files. I have changed upload_max_filesize, post_max_size, and memory_limit all to 8M and changed max_execution_time to 300. It still won't handle files more than a meg... It just uploads it then tells me that it is the wrong file type and refreshes the upload page. I tried taking out the part where it checks the file extension, but then it just refreshes the page after it uploads and nothing happens. No change to the DB, no file in my mp3 folder... Here is the relevent code:

     

    $upload_dir = "mp3/";
    $size_bytes = 8000000;
    $limit_file_type = "yes";
    $limitedext = array("audio/mpeg");
    
    if(!is_dir("$upload_dir"))
      {
       die("The directory <b>$upload_dir</b> doesn't exist");
      }
       if(!is_writeable("$upload_dir"))
        {
         die ("The MP3 directory is NOT writable, Please Chmod (777)");
        }
      if(is_uploaded_file($_FILES['mp3']['tmp_name']))
       {
        $size = $_FILES['mp3']['size'];
          if ($size > $size_bytes)
           {
            echo '<script>alert("File Too Large.");</script>';
            echo '<META http-equiv="refresh" content="0;URL=upload.php" target="_top">';
            exit();
           }
       }   // It seems to kick me out right here every time... 
     if (($limit_file_type == "yes") && (!in_array($_FILES['mp3']['type'],$limitedext)))
      {
       echo '<script>alert("wrong file type");</script>';
       echo '<META http-equiv="refresh" content="0;URL=upload.php" target="_top">';
       exit();
      }
    
    $filename =  $_FILES['mp3']['name'];
    if(file_exists($upload_dir.$filename))
    {
      echo '<script>alert("The filename already exists!");</script>';
      echo '<META http-equiv="refresh" content="0;URL=upload.php" target="_top">';
      exit();
     }
    
    $uploadto = 'mp3/';
    $uploadfile = $uploadto . basename($_FILES['mp3']['name']);
    
    if (move_uploaded_file($_FILES['mp3']['tmp_name'], $uploadfile))
      {
        include("connect.php");
        $sql = "INSERT INTO band_music (bm_type, bm_title, bm_desc, bm_file, bm_user, bm_date) VALUES '$bm_type', '$bm_title', '$bm_desc', '$filename', '$bm_user', '$bm_date')";
        $result = @mysql_query($sql,$connection) or die(mysql_error());
    
        echo '<script>alert("MP3 Uploaded Successfully!");</script>';
        echo '<META http-equiv="refresh" content="0;URL=refreshplaylist.php" target="_top">';	
      }
    }
    

     

    Please help! This is getting very frustrating!

     

    Thanks very much,

    - Jeff

  10. Hello everyone,

    I'm having a problem with my upload.php script... It is meant to upload an MP3 file and it works fine, with a few exceptions. Firstly, it doesn't check the file extension as it should. If I try to upload a wav, it doesn't give me an error (which it should). Secondly, I tried to upload a file that was 5.8 megs and it didn't go through. If I try a small file at about 1 MB, it works fine. POST_MAX_SIZE is at 8 MB, so I don't exactly know whats going on. Do I have to change my MAX_EXECUTION_TIME ? It is currently at 30. I'm running PHP 4.3.11. The relevent code is as follows:

     

    $upload_dir = "mp3/";
    $size_bytes = 8000000;
       	$extlimit = "yes";
       	$limitedext = array(".mp3");
    
    
    if(!is_dir("$upload_dir"))
    	{
         		 die("The directory <b>$upload_dir</b> doesn't exist");
             	}
            if(!is_writeable("$upload_dir"))
    	{
               	 die ("The MP3 directory is NOT writable, Please Chmod (777)");
             	}
    if(is_uploaded_file($_FILES['mp3']['tmp_name']))
    	{
            	 $size = $_FILES['mp3']['size'];
            	 if ($size > $size_bytes)
            		{
    		 echo '<script>alert("File Too Large.");</script>';
    	 	 echo '<META http-equiv="refresh" content="0;URL=upload.php" target="_top">';
                		 exit();
            		}
    	}
            if (($limit_file_type == "yes") && (!in_array($_FILES['mp3']['type'],$limitedext)))
            	{
    	 echo '<script>alert("wrong file type");</script>';
    	 echo '<META http-equiv="refresh" content="0;URL=upload.php" target="_top">';
                	 exit();
            	}
    
            $filename =  $_FILES['mp3']['name'];
            if(file_exists($upload_dir.$filename))
    	{
    	 echo '<script>alert("The filename already exists!");</script>';
    	 echo '<META http-equiv="refresh" content="0;URL=upload.php" target="_top">';
                	 exit();
            	}
    
    $uploadto = 'mp3/';
    $uploadfile = $uploadto . basename($_FILES['mp3']['name']);
    
    
    
    if (move_uploaded_file($_FILES['mp3']['tmp_name'], $uploadfile))
    	{
       		 include("connect.php");
    	 $sql = "INSERT INTO band_music (bm_type, bm_title, bm_desc, bm_file, bm_user, bm_date) VALUES ('$bm_type', '$bm_title', '$bm_desc', '$filename', '$bm_user', '$bm_date')";
    	 $result = @mysql_query($sql,$connection) or die(mysql_error());
    
    	 echo '<script>alert("MP3 Uploaded Successfully!");</script>';
    	 echo '<META http-equiv="refresh" content="0;URL=refreshplaylist.php" target="_top">';	
    	}
    
    
    }
    

     

    Any help is appreciated!

     

    Thanks in advance,

    - Jeff

  11. Hi,
    I have a product catalogue DB that includes fields for make, model, etc... There will be a lot of repetitiveness in the make field, for example, the make could be Ford and the model could be Ranger or F150 or whatever.

    The thing is that there WILL be multiple makes, just there will be many repetitions. What I need to do is to pull out each make, but only once so I can have a bulleted list of the makes w/o repetition. How can I do this?

    Thanks,
    - Jeff
  12. Hi,
    I have a portion of code in my PHP program that works on my personal server, but not on the freshly installed server here at work... Originally, my server had PHP version 4.3.11, whereas my new server has PHP 5.1.5. Here is the problem... This snippet of code no longer can pass the variables to the next page:

    [code=php:0]
    <a href="export.php?w=1&amp;month=<? echo $today_month; ?>&amp;year=<? echo $today_year; ?>&amp;listorder=<? echo $listorder; ?>&amp;filename=<? echo $thefilename; ?>" name="2excel" class="print" target="_blank"><img src="images/excel.gif" border="0"> <b>Export to Excel</b></a>
    [/code]

    However, when I use sessions, it works. I don't know what could be wrong... I'm thinking it has to do with configuration settings somehow, but I don't know what...

    Thanks,
    - Jeff
×
×
  • 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.