Jump to content

dreamwest

Members
  • Posts

    1,223
  • Joined

  • Last visited

    Never

Posts posted by dreamwest

  1. is it possible to scandir a random file??

     

    This code selects the first file found

    $dir = '/htdocs/user/site.com/thumbs/';
    foreach(scandir($dir) as $file){
    
    if (strtolower(substr($file, -4)) == '.jpg') {
    
    	if (file_exists($dir . $file)) {
    
    	$image = "/thumbs/".$file;
    	echo $image;
    
    	} else {
    	//default image
    	echo "There was an error getting the thumbnail ";
    	}
    }
    }//end foreach
    

  2. I need to transfer a file from one directory to another, but this script loads endlessly.

     

    $dir = "/htdocs/user/videos/";
    $backup = "/htdocs/user/backup/";
    
    $file = video.flv;
    
    //**check if file exists**//
    $filename = $dir . $file;
    
    if (file_exists($filename)) {
        echo "<font color\"green\">The file exists</font>";
    
    $current = file_get_contents($dir . $file);
    file_put_contents($backup . $file);
    
    }else{
    echo "no";
    }
    

  3. I have 2 server one with a database (no remote access) has file names stored and second with physical files

     

    I need to make a backup of 20,000 videos on the remote server.

     

    Local server:

     

    /htdocs/user/dir/ftp_script.php

     

    Remote server:

     

    /htdocs/user/dir/        //all videos here

    /htdocs/user/backup/  //transfer backup files here

     

    What ftp function can i do this with, the only way i can think of is to download the file to local server then reupload it to remote server

  4. Im trying to learn curl, but the script endlessly loads

     

    set_time_limit(0);
    
    // create a new cURL resource
    $ch = curl_init();
    
    // set default curl options
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
    curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
    curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookie.txt');
    curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.8.1.11) Gecko/20071127 Firefox/2.0.0.11");
    
    $g_url = http://site.com/page.html;
    
    echo "Fetching...<br>";
    curl_setopt($ch, CURLOPT_URL, $g_url);
    
    echo "test<br>";
    
    $html = curl_exec($ch);
    echo"test2";
    
    if (strlen($html)>0) {
    
    echo "ok";
    
    }
    

     

    This echos :

     

    Fetching...
    test

     

    Its sticking on this part for some reason:

     

    $html = curl_exec($ch);

     

  5. Im trying to delete multiple files by ftp, i can do this with a single file but how can i do it to delete multiple files

     

    $file = "image.jpg"; //deletes this single file
    //$files = array(image1.jpg, image2.jpg, image3.jpg);
    
    $target_ftp_server			= "server";
    $target_ftp_user			= "user";
    $target_ftp_pass			= "pass";
    $target_ftp_path_thumb	= "/";
    
    // connect to target ftp server
    $target_conn = ftp_connect($target_ftp_server) or die("Could not connect to target_ftp_server!");
    ftp_login($target_conn, $target_ftp_user, $target_ftp_pass);
    
    // switch to passive mode if behind a firewall 
    ftp_pasv($target_conn, true );
    
    // change to the target path
    ftp_chdir($target_conn, $target_ftp_path_thumb);
    
    // delete file
    if (ftp_delete($target_conn, $file)) {
    
    echo "<font color='red'>Removed!</font>";
    
    } else {
    echo "could not delete $file\n ";
    }
    
    // close all ftp connections
    ftp_close($target_conn);
    

  6. Im trying to make a query to tell how many videos each user has uploaded, but the there are two tables and i need to sort by amount of videos descending

     

    Heres what ive done

    $query = "SELECT videos.*, signups.* ".
    "FROM videos, signups ".
    "WHERE videos.user_id = signups.user_id limit 5 ";
    
    $result = mysql_query($query) or die(mysql_error());
    
    
    // Print out the contents of each row into a table 
    while($row = mysql_fetch_array($result)){
    echo $row['username']. " has ". $row['   ']." videos";
    echo "<br />";
    }
    

     

    Heres my table structure

     

    Table1:

    signups (tabe name)

     

    user_id  |  username

     

    Table 2:

    videos (Table name)

     

    id |  user_id 

     

     

    I proberly need a count or group in here but im uncertain

     

  7. Im trying import a txt file line by line

     

    Heres the txt file:

     

    one

    two

    three

    four

    five

     

    etc...

     

    Basically i want to import this into my database:

     

    $file_names = '/home/htdocs/file_names.txt';
    
    $sql = "INSERT INTO `forum` SET `username`='ghost' ";
    $result = mysql_query($sql) or die(mysql_error());
    

     

     

  8. If you have directories like this that broswers dont need to enter:

     

    /includes/

    /js/

    /images/

     

    etc...

     

    Boot the browser off with htaccess, redirect them to the root account.

     

    Your index.php page is the main target for hacking. Youll sometime see it with 777 permissions, if you dont update this page - chmod it to 444.

     

    Rember htaccess is you best friend  for fooling hackers as to what directory structure youve got by useing urlrewrite, its easier for them to go to a less confusing site - unless your worth hacking of course

     

    Use remote address to check the ip for admin panels so only allowing your ip into the admin panel

     

  9. Works fine when I test it (although I'm getting an expected "undefined index" notice when $_COOKIE['turbo'] doesn't exist). Just remember that the cookie is first available on the next page load.

     

    Thats why i added the

    echo "Completed! <a href=\"/\">Click here to test</a>";

    part

     

    Ive tested it on 3 browser and no cookie is set, although i can set cookies with javascript

     

    ...maybe an elusive bug....

     

  10. Im going round in circles trying to set a simple cookie, ive done this before but i cant get it to work. Can someone see my error??

     

    $expire=time()+60*60*24*30*30;
    setcookie("turbo", "on", $expire, "/");
    echo "Completed! <a href=\"/\">Click here to test</a>";
    
    if(!$_COOKIE['turbo']){
      echo 'its not there';
    }elseif($_COOKIE['turbo'] == "on" ){
      echo 'its on';
    }

  11. Im trying to only select files with a .jpg extension in a directory. Also i need to kill the script if it doesnt have any files with this extension in it.

     

    Heres what ive got so far

    $dir = '/home/user/public_html/pics/';
    
    foreach(scandir($dir) as $file){
    
    //kill the script if no files
    if ($file< 0){
    echo "No files";
    die();
    }
    
    //if $file has a .jpg extension do something here
    
    
    }

     

     

  12. Think about it...if you were him you would fake your own death, and live the second half of your life in peace....with more surgery

     

    Well that's one way to get the PTA off your back.

     

    If i was him i would do it. It wouldnt surprise me if someone found him a few years down the track.....as a woman

  13. Im trying to float this form to the right but it becomes inactive somethings stopping you from entering anything into the form.

     

     

    <style>
    .search{
    color:#777;
    display:block;
    font:bold 12px Arial;
    height:20px;
    margin-bottom:3px;
    padding:0 0 0 18px;
    float:right;
    margin-top: 20px;
    
    }</style>
    <div class="search">
    <form name="searchForm" action="/search.php" method="GET">
    <INPUT class=search_box tabIndex=1 maxLength=128 name="search_id" value="" size="31">
    <input style="background-color:#c0c0c0; margin-right: 15px;" type="submit"  value="Search">
    </form>
    </div>
    

  14. How can i have a div with an image inside that says "Loading...." until the image is actually loaded. Is this a body onload thing??

     

    <div class=loading" align="center">Loading Image....<div>
    <div class="image">
    <img border="0" src="http://img.site.com/image.jpg" width="25" height="25">
    </div>

  15. Im using num_rows to cound how many rows there are in a table, but is count(*) faster

     

    Heres what im using:

    $result3 = mysql_query("SELECT id FROM table WHERE approve='1' ")or die(mysql_error());
    $content_count = mysql_num_rows( $result3 );

     

    Also i cant seem to get count to work, it only select about 200 rows, but there are over 30,000 rows

     

    $content_count = mysql_query("SELECT COUNT(id) FROM table WHERE approve='1' ")or die(mysql_error());
    
    echo $content_count;

     

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