NamePros
Welcome, Guest! Ready to make a name for yourself in the domain business? We welcome both the hobbyist and professional domainer to join the discussion as part of the NamePros community.

Click here to create your profile to start earning reputation for posting, and trader ratings for buying & selling in our free e-marketplace. Build your trader rating with each successful sale. Our system has tracked over 100,000 sales and counting!
FAQ & TOS Register Search Today's Posts Mark Forums Read

Go Back   NamePros.com > Website Development Discussion Forums > Programming
Reload this Page Strange PHP error.

Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics.

Advanced Search


Closed Thread
 
LinkBack Thread Tools
Old 08-09-2005, 11:27 AM   #26 (permalink)
Professional Monkey
 
Amnezia's Avatar
Join Date: Jul 2005
Location: Escaped from the zoo
Posts: 907
Amnezia has a spectacular aura aboutAmnezia has a spectacular aura about
 


Cancer Survivorship Save a Life
does "uploads\\" not work?
__________________
Webmaster Words
Amnezia is offline  
Old 08-09-2005, 11:31 AM THREAD STARTER               #27 (permalink)
Senior Member
 
Barrucadu's Avatar
Join Date: Aug 2005
Location: East Yorkshire, England
Posts: 2,689
Barrucadu is a splendid one to beholdBarrucadu is a splendid one to beholdBarrucadu is a splendid one to beholdBarrucadu is a splendid one to beholdBarrucadu is a splendid one to beholdBarrucadu is a splendid one to beholdBarrucadu is a splendid one to behold
 




also, if i post a link related to www.ISC.tk dont click it, i havent got the domain set up yet.

someone help me with the search page please here it is:

PHP Code:
<?php
????: NamePros.com http://www.namepros.com/programming/114050-strange-php-error.html

$form 
"<form method=\"POST\" action=\"search.php\">";
$form .= "Search for: <input type=\"text\" name=\"criteria\">
             <input type=\"Submit\" name=\"Submit\" value=\"Submit\">"
;
$form .= "</form>";

// check is user submitted, if not, show the form
if ($_POST['Search'] != "Search")
{
    echo 
$form;
}
else
{

$directory "/uploads/";

if (
is_dir($directory))
{
   
$open_dir opendir($directory);
    while ((
$file readdir($open_dir)) !== false)
    {
        
// Place filenames into an array
        
$files[] = $file;
    }
    
closedir($open_dir);

    
// files are in an array, check if search criteria meets any names in array
    
if (in_array($_POST['criteria'], $files))
    {
        foreach (
$files AS $file_result)
        {
            if (
stristr($file_result$_POST['criteria']))
            {
                echo 
"File Found : <a href = \"/uploads/browseupload.php?file=".$file_result.">View Result</a>";
            }
        }
    }
    else
    {
        echo 
"Search Criteria not found<br /> Please try again<br /><br />";
????: NamePros.com http://www.namepros.com/showthread.php?t=114050
        echo 
$form;
    }
}

}

?>
its supposed to serach the uploads folder for a file, but it dosnt work
Last edited by Mikor; 08-09-2005 at 11:45 AM.
Barrucadu is offline  
Old 08-09-2005, 11:58 AM   #28 (permalink)
DNOA Member
Join Date: May 2004
Posts: 5,040
mholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant future
 


Autism Marrow Donor Program 9/11/01 :: Never Forget Multiple Sclerosis Adoption Alzheimer's Lou Gehrig's Disease (ALS)
Correct me if I'm wrong, but that !== you want maybe should be a != operator?

Otherwise I'm not too familiar with directory functions... :-/
mholt is offline  
Old 08-09-2005, 12:38 PM   #29 (permalink)
Professional Monkey
 
Amnezia's Avatar
Join Date: Jul 2005
Location: Escaped from the zoo
Posts: 907
Amnezia has a spectacular aura aboutAmnezia has a spectacular aura about
 


Cancer Survivorship Save a Life
you dont need the !==false at all

PHP Code:
if (is_dir($directory))
{
   
$open_dir opendir($directory);
    while (
$file readdir($open_dir))
    {
        
// Place filenames into an array
        
$files[] = $file;
    }
    
closedir($open_dir); 
????: NamePros.com http://www.namepros.com/showthread.php?t=114050
is correct

where did you get this script from it is possibly the messiest coding i've ever seen, lol. no offenece intended
__________________
Webmaster Words
Last edited by Amnezia; 08-09-2005 at 12:47 PM.
Amnezia is offline  
Old 08-09-2005, 01:05 PM   #30 (permalink)
NamePros Member
Join Date: Jan 2005
Location: Texas USA
Posts: 71
Outer is an unknown quantity at this point
 



http://us3.php.net/opendir



BTW Amnezia, your file extension check wont work for ALL files. Some files contain periods before the file extension, therefore, it will check everything AFTER that...

Try this code. It reverses the string and takes everything before the first period, then reverses it back to give you the correct file extension
????: NamePros.com http://www.namepros.com/showthread.php?t=114050

PHP Code:
<?php
function find_extension($file) {
   
$revfile strrev($file);
????: NamePros.com http://www.namepros.com/showthread.php?t=114050
   
$ext strtolowerstrrev(substr($revfile,0,strpos($revfile,"."))) );

   return 
$ext;
}

$allowed_extensions = array("gif""jpg""jpeg""png""bmp");
$extension find_extension($_FILES['uploadedfile']['name']);

if (
in_array($extension$allowed_extensions))
{
    
// The extension is valid
}
else
{
    
// Extension is not valid
    
echo "Dissallowed File Extension!"
    echo 
"<p>Allowed extensions are .gif, .jpg, .png and .bmp</p>"
    echo 
"<p><a href=\"Home.php\">Try Again</a></p>"
    die();
}
?>
__________________
I wonder...
Outer is offline  
Old 08-09-2005, 01:11 PM   #31 (permalink)
Professional Monkey
 
Amnezia's Avatar
Join Date: Jul 2005
Location: Escaped from the zoo
Posts: 907
Amnezia has a spectacular aura aboutAmnezia has a spectacular aura about
 


Cancer Survivorship Save a Life
Originally Posted by Outer
http://us3.php.net/opendir

BTW Amnezia, your file extension check wont work for ALL files. Some files contain periods before the file extension, therefore, it will check everything AFTER that...
yah im aware of that i just cleaned up the code previously used

????: NamePros.com http://www.namepros.com/showthread.php?t=114050
the best way to do it is to check the mime types of the files
__________________
Webmaster Words
Amnezia is offline  
Old 08-09-2005, 01:16 PM   #32 (permalink)
NamePros Member
Join Date: Jan 2005
Location: Texas USA
Posts: 71
Outer is an unknown quantity at this point
 



I actually use both...

Check file extension and MIME type.

This script works (probably not best methods on some parts, but still works nonetheless )

PHP Code:
<?php

$form 
"<form method=\"POST\" action=\"image_find.php\">";
$form .= "Search for: <input type=\"text\" name=\"criteria\">
             <input type=\"Submit\" name=\"Search\" value=\"Search\">"
;
$form .= "</form>";

// check is user submitted, if not, show the form
if ($_POST['Search'] != "Search")
{
    echo 
$form;
}
else
{

$directory "images/";

if (
is_dir($directory))
{
   
$open_dir opendir($directory);
    while (
$file readdir($open_dir))
    {
        
// Place filenames into an array
        
$files[] = $file;
    }
    
closedir($open_dir);

 

    
// files are in an array, check if search criteria meets any names in array
    
$i 0;
        foreach (
$files AS $file_result)
        {
            if (
eregi($_POST['criteria'], $file_result))
            {
????: NamePros.com http://www.namepros.com/showthread.php?t=114050
               
$echo .= "<a href=\"uploads/browseupload.php?file=".$file_result."\">".$file_result."</a><br />";
????: NamePros.com http://www.namepros.com/showthread.php?t=114050
               
$i++;
            }
        }

        if (
$i == "0")
        {
            echo 
"Search Criteria not met.<br /><br />";
            echo 
$form;
        }
        else
        {
            echo 
$echo."<br />";
            echo 
$form;
        }
}
else
{
    echo 
"Not a Directory!";
}

}

?>
__________________
I wonder...
Outer is offline  
Old 08-09-2005, 03:09 PM THREAD STARTER               #33 (permalink)
Senior Member
 
Barrucadu's Avatar
Join Date: Aug 2005
Location: East Yorkshire, England
Posts: 2,689
Barrucadu is a splendid one to beholdBarrucadu is a splendid one to beholdBarrucadu is a splendid one to beholdBarrucadu is a splendid one to beholdBarrucadu is a splendid one to beholdBarrucadu is a splendid one to beholdBarrucadu is a splendid one to behold
 




thanks for all the help everyone, ive just got one more problem:

PHP Code:
if(!"browseupload.php" == $entry && !"filemanager.php" == $entry) {
    echo 
"<p><b><u>File</u></b>";
    echo 
"<br><b>|----Name: </b>".$entry;
    echo 
"<br><b>|----Link: </b><a href = \"/Uploads/browseupload.php?file=".$entry."&admin=yes\">View Image</a>";
    echo 
"<br><b>|----Size: </b>".filesize($path."/".$entry)." bytes";
    echo 
"<br><b>|----<u>Actions</u></b>";
    echo 
"<br><b>|.....|----Delete: </b><a href = \"/Uploads/filemanager.php?file=".$entry."&action=880952delfile\">Go</a>";
    echo 
"<br><b>|.....|----Rename: </b><a href = \"/Uploads/filemanager.php?file=".$entry."&action=482975renfile\">Go</a>";

now, before i added in that if statement this code listed every file in the directory /Uploads/ i added in the if statement to remove two files from the list: browseupload.php and filemanager.php, now it doesnt work at all.
Last edited by Mikor; 08-09-2005 at 03:16 PM.
Barrucadu is offline  
Old 08-09-2005, 03:31 PM   #34 (permalink)
RJ
NamePros Webmaster


 
RJ's Avatar
Join Date: Feb 2003
Posts: 12,930
RJ Has achieved greatnessRJ Has achieved greatnessRJ Has achieved greatnessRJ Has achieved greatnessRJ Has achieved greatnessRJ Has achieved greatnessRJ Has achieved greatnessRJ Has achieved greatnessRJ Has achieved greatnessRJ Has achieved greatnessRJ Has achieved greatness
 



Find Marrow Donors! Cystic Fibrosis Parkinson's Disease
Try
PHP Code:
if ($entry != "browseupload.php" && $entry != "filemanager.php") { 
or to make one that will ignore any php files.
????: NamePros.com http://www.namepros.com/showthread.php?t=114050
PHP Code:
list($filenm$fileext) = split("\.",$entry2);
if (
strtolower($fileext) != "php") { 
Now stop spamming nationstates
__________________
@DomainBuyer facebook
RJ is offline  
Old 08-09-2005, 03:45 PM   #35 (permalink)
Eating Pie
 
iNod's Avatar
Join Date: Nov 2004
Location: Canada
Posts: 2,272
iNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud of
 


Special Olympics AIDS/HIV Cystic Fibrosis Save The Children Baby Health Cystic Fibrosis
The code I gave you nees to be edited to fit your script. Since the form field name is file insted of the regular userfile you will have the change $_FILES['userfile'].... to $_FILES['file']...

Other than that I can't see a problem why the code I didn't give you won't work.. It worked for me.
__________________
I feel old.
iNod is offline  
Closed Thread


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


Similar Threads
Thread Thread Starter Forum Replies Last Post
Tutorial: Getting started with PHP (The Basics) deadserious Webmaster Tutorials 60 11-17-2007 12:35 PM
Googlism - What does google think of you? deadserious The Break Room 55 12-15-2005 10:09 AM
PHP Error Unknown Programming 3 01-25-2005 10:06 PM

Liquid Web Smart Servers  
All times are GMT -7. The time now is 12:28 AM.

Managed Web Hosting by Liquid Web
Domain name forum recommended by Domaining.com Powered by: vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.6.0 Ad Management plugin by RedTyger