Jump to content

Reaper0167

Members
  • Posts

    270
  • Joined

  • Last visited

    Never

Posts posted by Reaper0167

  1. Sorry to bring this post back from the dead, but I was wondering if the line marked below can be eliminated? Couldn't I just have $fileType in the IF statement?

    <?php
    $allowed = array('image/bmp','image/x-png','image/jpg','image/gif');
    $imageType = $fileType;    // this line here
    if (!in_array($imageType,$allowed))
    ?>
    
    

  2. Just trying to limit file types on upload. This is not hard to do(maybe it is). No matter what file I choose, i get the error saying that it is the wrong type of file. Here is the code,,,,again...

    <?php
    session_start();
    include ("upload_db_info.php");
    if (!empty($_POST['upload']))
    {
    extract($_POST);
       	if(isset($_POST['upload']) && $_FILES['upload_file']['size'] < 500000)
    {
        	$fileName = $_FILES['upload_file']['name'];
           	$tmpName = $_FILES['upload_file']['tmp_name'];
           	$fileSize = $_FILES['upload_file']['size'];
           	$fileType = $_FILES['upload_file']['type'];
        	if ( file_exists($tmpName))
        	{
        		$content = file_get_contents($tmpName);
        	}
        }
    
    
    $allowed = array('.gif','.bmp');
    $fileName = $_FILES[$fileName]['name'];
    $imageType = strtolower(substr($fileName,-4));
    if (!in_array($imageType,$allowed))
    {
       		unset($_SESSION['uploadcomplete']);
    	$_SESSION['uploaderror'] = "<font color=red><font size=2>Please select a valid picture format under 500,000 bytes(.5 				 									 megabytes)";
    	header("location: http://www.----------.com");
    	exit();
    }
    
    
    $user = mysql_real_escape_string($user);      
    $trade = mysql_real_escape_string($trade);
    $picname = mysql_real_escape_string($picname);
    $fileName = mysql_real_escape_string($fileName);
        $fileSize = (int)$fileSize;
        $fileType = mysql_real_escape_string($fileType);
        $content  = mysql_real_escape_string($content);
        $descrip = mysql_real_escape_string($_POST["descrip"]);
    $trade = mysql_real_escape_string($_POST["trade"]);
    $picname = mysql_real_escape_string($_POST["picname"]);
    $query = "INSERT INTO UploadedFiles (name, size, type, content, user, descrip, trade, picname)VALUES('$fileName', 						 			 '$fileSize', '$fileType', '$content', '$user', '$descrip', '$trade', '$picname')";        
       	$result = mysql_query($query)or die (mysql_error());
        unset($_SESSION['uploaderror']);
    $_SESSION['uploadcomplete'] = "Your picture was uploaded to our system.";
        header("location: http://www.------------.com");
        exit();
    }
    ?>
    

  3. I would only like to be able to upload gif jpeg png jpg  Any other file type would get an error. Right now if the file is larger than .5mb, i will will recieve an error, which is good, that is working correctly. Just the files types I can't seem to get. Here is the script again.

    <?php
    session_start();
    include ("upload_db_info.php");
    
    if (!empty($_POST['upload']))
    {
    extract($_POST);
       		
    if(isset($_POST['upload']) && $_FILES['upload_file']['size'] < 500000)
    {
        	$fileName = $_FILES['upload_file']['name'];
            $tmpName = $_FILES['upload_file']['tmp_name'];
            $fileSize = $_FILES['upload_file']['size'];
            $fileType = $_FILES['upload_file']['type'];
        	if ( file_exists($tmpName) )
        	{
        		$content = file_get_contents($tmpName);
        	}
        }
        else
    {
    	unset($_SESSION['uploadcomplete']);
    	$_SESSION['uploaderror'] = "<font color=red><font size=2>Please select a valid picture format under 500,000 bytes(.5 				 									 megabytes)";
    	header("location: http://www.---------.com");
    	exit();
    }
    
    $user = mysql_real_escape_string($user);      
    $trade = mysql_real_escape_string($trade);
    $picname = mysql_real_escape_string($picname);
    
    $fileName = mysql_real_escape_string($fileName);
        $fileSize = (int)$fileSize;
        $fileType = mysql_real_escape_string($fileType);
        $content  = mysql_real_escape_string($content);
        $descrip = mysql_real_escape_string($_POST["descrip"]);
    $trade = mysql_real_escape_string($_POST["trade"]);
    $picname = mysql_real_escape_string($_POST["picname"]);
    
    $query = "INSERT INTO UploadedFiles (name, size, type, content, user, descrip, trade, picname)VALUES('$fileName', '$fileSize',                                        '$fileType', '$content', '$user', '$descrip', '$trade', '$picname')";        
        $result = mysql_query($query)or die (mysql_error());
        
    unset($_SESSION['uploaderror']);
    $_SESSION['uploadcomplete'] = "Your picture was uploaded to our system.";
        header("location: http://www._________-.com");
        exit();
    }
    ?>
    

  4. ok, here it is. i have a db with table that consists of pics, description and the username of who uploaded. i would like each user to view a page that shows which pic they uploaded. so i think i need to find all the images in the database with the field of their username. right? any ideas

  5. don't understand why that would make a difference. here is the code with the onfocus for the text boxes removed. everything loads just fine.

    <table width="950" border="0" align="center" cellpadding="0" cellspacing="0">
      <tr>
        <th height="297" scope="col"><div id="header"><img src="images08/header.png" alt="header" width="421" height="47" /></div>
          <div id="apDiv1">
            <?php
            session_start();
            if(isset($_SESSION['auth']))
            {
          	  echo $_SESSION['message'];
            }
            else
            {
          	   echo '<form name="form1" method="post" action="login.php">
    			 <input name="username" type="text" id="username" value="User ID"  />
    			 <input name="password" type="password" id="password" value="Password"  />
    			 <input type="submit" name="submit" id="submit" value="Login">
    			 <br />
    			 Not registered? <a href="register.php">Register Now!</a>
    			 </form>';
      	    }
    	    ?>
        </div></th>
      </tr>
    </table>
    

    i get the error when the 2 lines are changed to this

     

    <input name="username" type="text" id="username" value="User ID" onfocus="this.value='';" />

    <input name="password" type="password" id="password" value="Password" onfocus="this.value='';" />

     

  6. i removed the php tags.here i what i got.. still an error.

    <table width="950" border="0" align="center" cellpadding="0" cellspacing="0">
      <tr>
        <th height="297" scope="col"><div id="header"><img src="images08/header.png" alt="header" width="421" height="47" /></div>
          <div id="apDiv1">
            <?php
            session_start();
            if(isset($_SESSION['auth']))
            {
          	  echo $_SESSION['message'];
            }
            else
            {
          	   echo '<form name="form1" method="post" action="login.php">
    			 <input name="username" type="text" id="username" value="User ID" onfocus="this.value='';"  />
    			 <input name="password" type="password" id="password" value="Password" onfocus="this.value='';" />
    			 <input type="submit" name="submit" id="submit" value="Login">
    			 <br />
    			 Not registered? <a href="register.php">Register Now!</a>
    			 </form>';
      	    }
    	    ?>
        </div></th>
      </tr>
    </table>
    

    still getting an error with this line

    <input name="password" type="password" id="password" value="Password" onfocus="this.value='';" />

     

  7. here is the full code for the table i have everything in

    <?php // this start tag is not in my code,, just put it there for you
    <table width="950" border="0" align="center" cellpadding="0" cellspacing="0">
      <tr>
        <th height="297" scope="col"><div id="header"><img src="images08/header.png" alt="header" width="421" height="47" /></div>
          <div id="apDiv1">
            <?php
            session_start();
            if(isset($_SESSION['auth']))
            {
          	  echo $_SESSION['message'];
            }
            else
            {
          	   echo '<?php 
    	   		 <form name="form1" method="post" action="login.php">
    			 <input name="username" type="text" id="username" value="User ID" onfocus="this.value='';"  />
    			 <input name="password" type="password" id="password" value="Password" onfocus="this.value='';" />
    			 <input type="submit" name="submit" id="submit" value="Login">
    			 <br />
    			 Not registered? <a href="register.php">Register Now!</a>
    			 </form>';
      	    		 ?>
    	}
    	    ?>
        </div></th>
      </tr>
    </table>
    ?> // same with this tag
    

    now you can get a better look at why it is not working.

  8. this doesn't work

    echo '<?php 
    	   		 <form name="form1" method="post" action="login.php">
    			 <input name="username" type="text" id="username" value="User ID" onfocus="this.value='';"  />
    			 <input name="password" type="password" id="password" value="Password" onfocus="this.value='';" />
    			 <input type="submit" name="submit" id="submit" value="Login">
    			 <br />
    			 Not registered? <a href="register.php">Register Now!</a>
    			 </form>';
      	    		 ?>
    

    but this does work,, what is going on?

    <?php
    <form name="form1" method="post" action="login.php">
    <input name="username" type="text" id="username" value="User ID" onfocus="this.value='';"  />
    <input name="password" type="password" id="password" value="Password" onfocus="this.value='';" />
    <input type="submit" name="submit" id="submit" value="Login">
    <br />
    Not registered? <a href="register.php">Register Now!</a>
    </form>
    ?>
    

    when i echo out the form i get an error

    Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting ',' or ';' in D:\-----\-----\html\------\index.php on line 35

    here is line 35

    <input name="username" type="text" id="username" value="User ID" onfocus="this.value='';"  />

    should something be different when echoing out the form while using the onfocus

     

     

  9. checking for the username and password would be inside of my login.php

    i'm just looking for the login form if no one is logged in and a welcome statement if someone is logged in. this is what i have so far. i don't think that i am echoing out the form correctly though.

    <?php
    session_start();
    if(isset($_SESSION['auth']))
    {
          echo "Welcome $username  Log Out";    //Need to make Log Out a link
    }
    else
    {
          echo "<form name="form1" method="post" action="login.php">
      <input type="text" name="username" id="username">
      <input type="text" name="password" id="password">
      <input type="submit" name="submit" id="submit" value="Login">
      </form>"
    }
    ?>
    

  10. i know about sessions and <?php

                                        if(isset($_SESSION['loggedIn'])) {

                                        // show relevant information

                                        }else{

                                        // show login form

                                        }

                                        ?>

    i see some code with EOD, is that something i should look into also

  11. Unable to open file at location...... that is the error now.

    <?php 
    include "msdata.php";
    
    $PSize = filesize($location); 
    $fh = fopen($location, "r") or die("Unable to open file at location.");
    $location = addslashes(fread($fh, $PSize)); 
    
    mysql_connect($host,$username,$password) or die("Unable to connect to MySQL."); 
    mysql_select_db($db_name) or die("No database found."); 
    mysql_query("INSERT INTO $tbl_name(pic)VALUES('$location')") or die("Operation unable to perform."); 
    
    ?>
    

  12. Could anyone point me in the right direction for a decent upload script. And then also linking a member back to what he/she uploaded. After a user uploads some pictures(picture, name, description of pic), they could go to a page to see just what they uploaded. Or they could also just view all the pics that all the users uploaded. Is this just way to difficult to do....When a user uploads a picture they get to pick from a list of categories that the picture would go in.

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