Jump to content

hellonoko

Members
  • Posts

    213
  • Joined

  • Last visited

Posts posted by hellonoko

  1. I am trying to write a query that selects all rows entered less than a day ago by comparing the field that states when the row was created against the current date/time minus 1 day.

     

    What is the proper way to do this as my query is failing.

     

    Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home2/sharingi/public_html/scrape/display/display.php on line 167
    

     

    <?php
    
    
    	$current_time = strtotime("now");
    
    	//take one day in seconds from the current time to find the timestamp for 24 hours ago
    	$day_old = $current_time - 86400;			
    
    	//change timetamp to a date format to compare
    	$day_old = date("Y-m-d H:i:s", $day_old);
    
    	echo $day_old;
    	// select all entries that are less than the 1 day old
    	$query = mysql_query("SELECT * FROM `mp3links` WHERE `foundtime` < $day_old AND `scraped` != '0' ORDER BY `foundtime` DESC");
    
    ?>

     

     

  2. I have no idea about classes really but looking at the PHP manual maybe you need to call the class first before you use a function that is part of it?

     

    so..

     

    $imgResize = new ImageResize;

     

    and then... image_scale

     

    or maybe....

     

    $result = $imgResize->{$imageResize->image_scale}();

     

    http://au2.php.net/zend-engine-2.php

     

    <?
    class Foo {
        public $aMemberVar = 'aMemberVar Member Variable';
        public $aFuncName = 'aMemberFunc';
        
        
        function aMemberFunc() {
            print 'Inside `aMemberFunc()`';
        }
    }
    
    $foo = new Foo;
    ?>
    
    You can access member variables in an object using another variable as name:
    <?
    $element = 'aMemberVar';
    print $foo->$element; // prints "aMemberVar Member Variable"
    ?>
    
    or use functions:
    <?
    function getVarName()
    { return 'aMemberVar'; }
    
    print $foo->{getVarName()}; // prints "aMemberVar Member Variable"
    ?>
    
    Important Note: You must surround function name with { and } or PHP would think you are calling a member function of object "foo".
    
    you can use a constant or literal as well:
    <?
    define(MY_CONSTANT, 'aMemberVar');
    print $foo->{MY_CONSTANT}; // Prints "aMemberVar Member Variable"
    print $foo->{'aMemberVar'}; // Prints "aMemberVar Member Variable"
    ?>
    
    You can use members of other objects as well:
    <?
    print $foo->{$otherObj->var};
    print $foo->{$otherObj->func()};
    ?>
    
    You can use mathods above to access member functions as well:
    <?
    print $foo->{'aMemberFunc'}(); // Prints "Inside `aMemberFunc()`"
    print $foo->{$foo->aFuncName}(); // Prints "Inside `aMemberFunc()`"
    ?>

     

     

  3. I am using a simple query that I have basically copied from another part of my code where it works perfectly but for some reason I can't see it errors now:

    <?php
    
    // connect the db
    include_once "connectotron.php";
    
    echo 'updating file sizes...<br>';
    
    $query = mysql_query("SELECT * FROM `mp3links` WHERE `scraped` = '1'");
    
    while ($row = mysql_fetch_array($query))
    {
    
    	$file =  '/home2/sharingi/public_html/scrape/scraped/'.$row[sourcefile];
    
    	echo $file_size = filesize($file);
    	echo '<br>';
    
    	$update = $row[sourcefile];
    
    	// set the file size
    	$query = "UPDATE `mp3links` SET `size` = '$file_size' WHERE `sourcefile` = '$update'";
    	$result = mysql_query($query) or die (mysql_error());
    
    }
    ?>

     

    Error:

    Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home2/sharingi/public_html/scrape/update_sizes.php on line 10

     

    When I comment out the last two lines of my code it works fine listing all the file sizes. Is there something wrong with my update query I cant see?

     

    Thanks

  4. I have the below simple code that I use to copy remote files.

     

    It allows me to copy a file even if its larger than expected or with slower connection as I am copying mp3 and sometimes they are 100megs sometimes 4megs.

     

    However when I came across this link:

    this.bigstereo.net/wp-content/uploads/2009/04/stomp-yo-shoes-bloody-beetroots-remix-the-aston-shuffle-vocal-edit-1.mp3

     

    My script basically hangs although the link is not broken and downloads perfectly.

     

    What I have noticed is that the other links load in my browser with quicktime and this link load as a Save As... dialog.

     

    Any ideas?

    Is there a better method I can be using to remotely copy files while still not worrying about the max_execution_time and max_file_size?

     

    Thanks.

     

    function copyFile($url,$dirname)
    {
    
    $url = str_replace(' ', '%20', $url);
    //$url = urlencode($url);
    
    @$file = fopen ($url, "rb");
    if (!$file) 
    {
    	echo "Failed to copy $url !";
    
    	return false;
    }
    else 
    {	
    	//copy file
    	$filename = basename($url);
    	$fc = fopen($dirname."$filename", "wb");
    	while (!feof ($file)) 
    	{
    		$line = fread ($file, 1028);
    		fwrite($fc,$line);
    	}
    
    	fclose($fc);
    	//echo "File $url saved to PC!";
    
    	$time_end = microtime(true);
    	$time = $time_end - $time_start;
    
    	if ( $time > 60 )
    	{
    		$time = $time / 60;
    		echo "File: $filename coppied in $time minutes";
    	}
    	else
    	{
    		echo "File: $filename coppied in $time seconds";
    	}
    
    	return true;
    }
    }

  5. Hmmm good idea. For now the only error I am getting is on spaces (i think)

     

    I can always add str_replaces I suppose.

     

    Is there a way I could find out what characters fopen and those functions do not like?

     

     

     

     

  6. Basically the links are in the DB as links without http://

    In whatever format they where crawled from a page in but put into the DB with mysql_real_escape_string();

     

    <?php
    //get the link to copy from the DB
    	$query = "SELECT * FROM `mp3links` WHERE `scraped` = 0 LIMIT 1";
    	$result = mysql_query($query);
    	$row = mysql_fetch_array($result) or die (mysql_error());
    
    	$url = "http://".$row[link];
    	$last_slash = strripos( $url ,"/");
    	$clean_file_name = substr( $url , $last_slash + 1 , strlen($url) );
    
    
    	// do a file copy
    	//$url = "http://www.beachtitti.com/summermix_01.mp3";
    	$dirname = "/home2/sharingi/public_html/scrape/scraped/";
    
    	// close th mysql connection because a large file copy may time out mysql
    	mysql_close($connection);
    
    	$result = copyFile($url , $dirname);
    
    ?>
    

    <?php
    function copyFile($url,$dirname)
    {
    
    //$url = urlencode($url);
    
    @$file = fopen ($url, "rb");
    if (!$file) 
    {
    	echo "Failed to copy $url !";
    
    	return false;
    }
    else 
    {	
    	//copy file
    	$filename = basename($url);
    	$fc = fopen($dirname."$filename", "wb");
    	while (!feof ($file)) 
    	{
    		$line = fread ($file, 1028);
    		fwrite($fc,$line);
    	}
    
    	fclose($fc);
    	//echo "File $url saved to PC!";
    
    	$time_end = microtime(true);
    	$time = $time_end - $time_start;
    
    	if ( $time > 60 )
    	{
    		$time = $time / 60;
    		echo "File: $filename coppied in $time minutes";
    	}
    	else
    	{
    		echo "File: $filename coppied in $time seconds";
    	}
    
    	return true;
    }
    }
    ?>

  7. :'(y URLS with spaces fail to be processed by fopen fread fwrite etc.

     

    EX:

    www.trashmenagerie.com/audio/Freak You/Freak You - From Nowhere.mp3

     

    However if I paste this link into my browser it becomes:

     

    http://www.trashmenagerie.com/audio/Freak%20You/Freak%20You%20-%20From%20Nowhere.mp3

     

    And works fine.

     

    Which of the url encoding functions do I need to be using to fix these urls before I process them?

     

    Thanks

     

  8. I am using the below simple code to copy remote files:

    <?php
    $copydir = "/home2/sharingi/public_html/scrape/scraped/";
    
    $data = file_get_contents($url);
    $file = fopen($copydir . $clean_file_name, "w+");
    fputs($file, $data);
    fclose($file);
    ?>
    

     

    However when I am attempting  to copy a certain file. I run into a situation where the file does not load or error for quite some time and so the MySql code after my copy code times out.

     

    Warning: file_get_contents(http://www.theliverhearts.com/audio/02%20Local%20Lift.mp3) [function.file-get-contents]: failed to open stream: HTTP request failed! in /home2/sharingi/public_html/scrape/copy.php on line 36
    MySQL server has gone away

     

    I am wondering what the best way to copy a remote file would be so that I can handle these situations and other file errors.

     

    Perhaps CURL?

     

     

     

     

  9. Why dont you use md5() and rand() and time() all together.

     

    I saw a good one where the code used the ip of the person visiting the page as part of the salt also.

     

    And why isnt comparing them to the used ones a good idea? Seems like you'd want to do that no matter how long or random your passwords are to make sure they are unique?

  10. Trying to select the record with the oldest time stamp from my table.

     

    <?php
    $query = "SELECT * FROM `blogs` ORDER BY `lastchecked` DESC LIMIT 1";
    $row = mysql_fetch_array($query) or die (mysql_error());
    
    $url = $row[url];
    ?>

     

    Returns:

    Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home2/sharingi/public_html/scrape/process_blogs.php on line 4

     

    Something obvious im missing? Thanks.

     

  11. My script inserts crawled links from a age into my DB.

    <?php 
    if (mysql_num_rows(mysql_query("SELECT * FROM `secondarylinks` WHERE link = '".mysql_real_escape_string($link)."' LIMIT 1")) == 0)
    	{
    		$query = "INSERT INTO `secondarylinks` ( `link` , `scraped` , `host` ) VALUES ( '".mysql_real_escape_string($link)."'' , '0' , '$site')";
    		$result = mysql_query($query) or die (mysql_error());
    	}
    ?>

     

    However I am receiving the following error:

    You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '0' , 'empreintes-digitales.fr')' at line 1

     

    When it tries to insert this url:

    ?tags=valerie je t'aime

     

    Is there something I should do besides

    mysql_real_escape_string()

     

    Before using mysql_real_escape_string() my script would return the URL as

    aime

     

    Any ideas?

×
×
  • 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.