Live Chat & Podcast at 1:00PM Eastern on Sunday!
There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
Search
Web Design & Development
Tag Cloud
access acer asus bios bsod computer crash desktop dns driver drivers error ethernet excel freeze gaming graphics hard drive hardware hdmi internet laptop malware memory monitor motherboard network printer problem ram registry repair router slow software sound trojan ubuntu 11.10 uninstall usb video virus vista wifi windows windows 7 windows 7 32 bit windows 7 64 bit windows xp wireless
Search
Search for:
Tech Support Guy Forums > Internet & Networking > Web Design & Development >
Data files and includes in arrays

Reply  
Thread Tools
dudeking's Avatar
Member with 483 posts.
 
Join Date: Feb 2007
Location: UK, Midlands
Experience: Advanced
26-May-2007, 07:23 AM #1
Data files and includes in arrays
How can I export to a data file?
I want a input feild where people can type in youtube codes for example; wXkna1u_9mg.

I want it to then store them in a data file as if it was an array so like:

'wXkna1u_9mg',
'ZAekTEyH2Hc',
'x9pH160_oy8'

then I believe if I make an array of

$videos = array(include($site.'/include/site/videos/videos.dat));

it will look the same as

$videos = array('wXkna1u_9mg', 'ZAekTEyH2Hc', 'x9pH160_oy8');
__________________
Thanks, Eddie
Software Engineering Student, NTU
dudeking's Avatar
Member with 483 posts.
 
Join Date: Feb 2007
Location: UK, Midlands
Experience: Advanced
26-May-2007, 07:42 AM #2
PHP Code:
<?php
    $site 
"http://safeinaroom.co.uk";
?>
<table id="mainscripttable" cellpadding="0" cellspacing="0" border="0">
    <tr>
        <td id="scripttitle">
            Videos - Pick a gallery
        </td>
    </tr>
    <!--Main Video Window-->
    <tr>
        <td id="mainscriptwindow">
            <?php
                $videos 
= array('wXkna1u_9mg','ZAekTEyH2Hc','x9pH160_oy8');
                if(
array_key_exists($_GET['video'], $videos))
                {
            
?>
            <object width="425" height="350">
                <param name="movie" value="http://youtube.com/v/<?php echo $videos[$_GET['video']]; ?>">
                </param>
                <param name="wmode" value="transparent">
                </param>
                <embed src="http://youtube.com/v/<?php echo $videos[$_GET['video']]; ?>" type="application/x-shockwave-flash" wmode="transparent" width="425" height="350">
                </embed>
            </object>
            <br>
            <?php    
                
}
            
?> 
        </td>
    </tr>
    <!--End-->
    <tr>
        <td>
            <div id="galleryselect">
                <table id="selecttable" cellpadding="0" cellspacing="5" border="0">
                    <tr>
                        <?php
                            
foreach($videos as $key);
                            {
                        
?>
                        <td>
                            <a href="?video=0">
                                <img src="http://img.youtube.com/vi/<?php echo $videos[$_GET['video']]; ?>/2.jpg" border="0" />
                            </a>
                        </td>
                        <?php
                            
}
                        
?>
                    </tr>
                </table>
            </div>
        </td>
    </tr>
</table>
I have that so far, not at all sure how to get the link to equal the possition of the video in the array, so the first video will be ?video=0 then ?video=1 ?video=2 etc...

Last edited by dudeking; 26-May-2007 at 08:04 AM..
dudeking's Avatar
Member with 483 posts.
 
Join Date: Feb 2007
Location: UK, Midlands
Experience: Advanced
26-May-2007, 08:04 AM #3
MMJ's Avatar
MMJ MMJ is offline
Senior Member with 3,637 posts.
 
Join Date: Oct 2006
26-May-2007, 01:03 PM #4
This is the video page:
PHP Code:
<?php
    $videos 
file('ytvids.txt');
    if(
array_key_exists($_GET['video'], $videos))
    {
        
?>
        <object width="425" height="350">
        <param name="movie" value="http://youtube.com/v/$address">
        </param>
        <param name="wmode" value="transparent">
        </param>
        <embed src="http://youtube.com/v/<?php echo $videos[$_GET['video']]; ?>" type="application/x-shockwave-flash" wmode="transparent" width="425" height="350">
        </embed>
        </object>
        <br>
        <?php
        
    
}
    else
    {
        echo 
'<div class="title">Select a Video Below</div>';
    }
    foreach(
$videos as $key => $value)
    {
        
printf('<a href="?video=%s">%s</a> '$key$key);
    }
?>
This is the insert form:
PHP Code:
<?php
if ($_GET['do'] == 'write')
{
    
$file=fopen("ytvids.txt","a+");
    if (
filesize("ytvids.txt") == 0)
    
$write fwrite($file"$_POST[ytcode]");
    else
    
$write fwrite($file"\r\n$_POST[ytcode]");
    if (!
$write)
        die (
"Error");
    else
    {
        
fclose($file);
        echo 
$_POST['ytcode'] . " Has been added!";
    }
}
else
    echo
    
'<form action="?do=write" method="post">
    <input type="text" name="ytcode" />
    <input type="submit" value="Insert" />'
;
?>
I tested both, they should work. Good luck!
brendandonhu's Avatar
Distinguished Member with 15,988 posts.
 
Join Date: Jul 2002
Location: Ann Arbor, MI
Experience: Advanced
27-May-2007, 06:07 AM #5
You should add some kind of validation on your insert form. Otherwise, somebody could add HTML to mess with your site, add long codes to fill up your hosting space, etc.
dudeking's Avatar
Member with 483 posts.
 
Join Date: Feb 2007
Location: UK, Midlands
Experience: Advanced
27-May-2007, 06:19 AM #6
I was thinking of that but there dosnt seem to be any pattern with the youtube codes. I think I'll just limit them to 10chariters and disallow < and >.

I plan to have the insert form password protected any way so only friends can add videos.

Also with that script ^^ it works but gives these messages:
Notice: Undefined index: video in /home/fhlinux170/s/safeinaroom.co.uk/user/htdocs/videos.php on line 3
Notice: Undefined index: do in /home/fhlinux170/s/safeinaroom.co.uk/user/htdocs/videos.php on line 29
__________________
Thanks, Eddie
Software Engineering Student, NTU
brendandonhu's Avatar
Distinguished Member with 15,988 posts.
 
Join Date: Jul 2002
Location: Ann Arbor, MI
Experience: Advanced
27-May-2007, 06:28 AM #7
Just add error_reporting(E_ALL ^ E_NOTICE); to the beginning of your script and it will ignore the notices.
dudeking's Avatar
Member with 483 posts.
 
Join Date: Feb 2007
Location: UK, Midlands
Experience: Advanced
27-May-2007, 06:35 AM #8
Okies, thanks

I'll do that but is there anyway I can define the indexs?
brendandonhu's Avatar
Distinguished Member with 15,988 posts.
 
Join Date: Jul 2002
Location: Ann Arbor, MI
Experience: Advanced
27-May-2007, 06:37 AM #9
They're defined when your form is submitted. Other than that, there's no need to define them.
MMJ's Avatar
MMJ MMJ is offline
Senior Member with 3,637 posts.
 
Join Date: Oct 2006
27-May-2007, 06:41 AM #10
Quote:
Originally Posted by brendandonhu
You should add some kind of validation on your insert form. Otherwise, somebody could add HTML to mess with your site, add long codes to fill up your hosting space, etc.
Are you talking to me?
brendandonhu's Avatar
Distinguished Member with 15,988 posts.
 
Join Date: Jul 2002
Location: Ann Arbor, MI
Experience: Advanced
27-May-2007, 07:06 AM #11
Looks like he's figured it out
Quote:
Originally Posted by dudeking
I was thinking of that but there dosnt seem to be any pattern with the youtube codes. I think I'll just limit them to 10chariters and disallow < and >.
dudeking's Avatar
Member with 483 posts.
 
Join Date: Feb 2007
Location: UK, Midlands
Experience: Advanced
27-May-2007, 07:35 AM #12
Yeah I've worked it out

Thanks for your help, could some one please help me in my other thread and tell me how to enable globals?

Thanks Eddie
dudeking's Avatar
Member with 483 posts.
 
Join Date: Feb 2007
Location: UK, Midlands
Experience: Advanced
27-May-2007, 10:16 AM #13
http://safeinaroom.co.uk/include/sit...ideoscript.php

It works there but when its included into the page I want it displayed in

http://safeinaroom.co.uk/videos/

It dosnt work...what up with that??
brendandonhu's Avatar
Distinguished Member with 15,988 posts.
 
Join Date: Jul 2002
Location: Ann Arbor, MI
Experience: Advanced
27-May-2007, 04:25 PM #14
We need to see the code for that page to tell what the problem is.
dudeking's Avatar
Member with 483 posts.
 
Join Date: Feb 2007
Location: UK, Midlands
Experience: Advanced
27-May-2007, 07:22 PM #15
PHP Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <?php
            $site 
"http://safeinaroom.co.uk";
        
?>
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
        <title>
            Safe In A Room - Videos
        </title>
        <link href="/style/style.css" rel="stylesheet" type="text/css" />
    </head>
    <body>
        <center>
            <table id="texttable" cellpadding="0" cellspacing="0" border="0">
                <tr>
                    <td colspan="4" id="header">
                    </td>
                </tr>
                <tr>
                    <td id="emokid">
                        <?php
                            
include($site.'/include/site/links.php');
                        
?>
                    </td>
                    <td id="lefttext">
                    </td>
                    <td id="textcel">
                        <?php
                            
include($site.'/include/site/videos/videoscript.php');
                        
?>
                    </td>
                    <td id="righttext">
                    </td>
                </tr>
                <tr>
                    <td id="footer" colspan="4">
                        <?php
                            
include($site.'/include/site/footer.php');
                        
?>
                    </td>
                </tr>
            </table>
        </center>
        <div id="corner">
        </div>
    </body>
</html>
Reply

THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.

Search Tech Support Guy

Find the solution to your
computer problem!




Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
WELCOME TO TECH SUPPORT GUY! Are you looking for the solution to your computer problem? Join our site today to ask your question -- for free! Our site is run completely by volunteers who want to help you solve your computer problems. See our Welcome Guide to get started.
Thread Tools



Facebook Facebook Twitter Twitter TechGuy.tv TechGuy.tv Mobile TSG Mobile
You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 09:44 PM.
Copyright © 1996 - 2011 TechGuy, Inc. All rights reserved.

Powered by Cermak Technologies, Inc.