Jump to content

CircularStopSign

Members
  • Posts

    44
  • Joined

  • Last visited

Posts posted by CircularStopSign

  1. for the extensions i just built a simple if statement... i dunno if its safe or w/e but its whati go fo rnow

    [code]
    if($FnameExt==$ext_array[0] || $FnameExt==$ext_array[1] || $FnameExt==$ext_array[2] || $FnameExt==$ext_array[3] || $FnameExt==$ext_array[4]){


    if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path.'/'.$randomName.".".$FnameExt)) {
        echo htmlentities('<a href="http://www.hostmapics.com/"><img src="http://hostmapics.com/');
    echo $target_path.'/'.$randomName.".".$FnameExt;
    echo htmlentities('"></a>');
    }
    else{
        echo "There was an error uploading the file, please try again!";
    }
    }
    else{
    echo "Not a valid file extension";
    }
    [/code]

    when i get to the directories i am either going to use a database or do a random 1-1000 to pick which folder the image is going in
  2. alright, thanks a lot that really helped, i'll give you my  code just so you can see it if youd like.
    [code]
    <?php
    $Fname=$_FILES['uploadedfile']['name'];


    //Function to strip the extension of a filename string
    function strip_ext($name)
      {
      $ext = strrchr($name, '.');
      if($ext !== false)
      {
      $name = substr($name, 0, -strlen($ext));
    }
    return $name;
    }
    // This will get the extension of the filename
    $FnameExt= end(explode('.',$Fname));

    function createRandomName() {

        $chars = "abcdefghijkmnopqrstuvwxyz023456789";
        srand((double)microtime()*10000000);
        $i = 0;
        $pass = '' ;

        while ($i <= 7) {
            $num = rand() % 33;
            $tmp = substr($chars, $num, 1);
            $pass = $pass . $tmp;
            $i++;
        }

        return $pass;

    }

    // Usage
    $randomName = createRandomName();

    //retrieve file name



    // Where the file is going to be placed
    $target_path = "images";

    /* Add the original filename to our target path. 
    Result is "uploads/filename.extension" */
    $target_path = "images";
    $_FILES['uploadedfile']['tmp_name'];



    if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path.'/'.$randomName.".".$FnameExt)) {

    //show the user their link
        echo htmlentities('<a href="http://www.hostmapics.com/"><img src="http://hostmapics.com/');
        echo $target_path.'/'.$randomName.".".$FnameExt;
        echo htmlentities('"></a>');
    } else{
        echo "There was an error uploading the file, please try again!";
    }
    ?>
    [/code]

    heres what i need to work on now:
    -an extension verification script
    -use a database or random selection for dir 1-1000 for the images/****/name.ext
    what else do i need?

    and should i use classes or should i just do everything on this page like i am now?



  3. i changed it to "basename($_FILES['randomName']..." then changed the rest of the "uploadedfile" to randomName also, but im guessing that doesnt work because it doesnt recognize the file because from the form i named it "uploadedfile" so i need somehow to change it from uploadedfile to a randomName...? maybe thats not what you were saying?
  4. i've looked all over, but i cant figure out how i would change the file name to a randomly generated name... heres my code so far

    [code]
    <?php

    function createRandomName() {

        $chars = "abcdefghijkmnopqrstuvwxyz023456789";
        srand((double)microtime()*10000000);
        $i = 0;
        $pass = '' ;

        while ($i <= 7) {
            $num = rand() % 33;
            $tmp = substr($chars, $num, 1);
            $pass = $pass . $tmp;
            $i++;
        }

        return $name;

    }

    $randomName = createRandomName();




    // Where the file is going to be placed
    $target_path = "images/";

    /* Adding the original filename to my target path. 
    Result is "uploads/filename.extension" */
    $target_path = $target_path . basename($_FILES['uploadedfile']['name']);

    $_FILES['uploadedfile']['tmp_name'];


    if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
        echo htmlentities('<a href="http://www.hostmapics.com/"><img src="http://hostmapics.com/');
    echo $target_path;
    echo htmlentities('"></a>');
    } else{
        echo "There was an error uploading the file, please try again!";
    }
    ?>
    [/code]

    incorperate the random name and how to rename the file just uploaded?

    thanks
  5. alright guys, this is finally what iput down and it works. thanks guys

    [code]
    if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
        echo htmlentities('<a href="http://www.hostmapics.com/"><img src="http://hostmapics.com/');
    echo $target_path;
    echo htmlentities('"></a>');
    } else{
        echo "There was an error uploading the file, please try again!";
    }[/code]
  6. hey i'm working on a public upload site and for some reason it just says "There was an error uploading the file, please try again!" whenever i try to upload something

    [code]

    // Where the file is going to be placed
    $target_path = "images/";

    /* Add the original filename to our target path. 
    Result is "uploads/filename.extension" */
    $target_path = $target_path . basename( $_FILES['uploadedfile']['name']);
    $_FILES['uploadedfile']['tmp_name']; 

    if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
        echo "The file ".  basename( $_FILES['uploadedfile']['name']).
        " has been uploaded";
    } else{
        echo "There was an error uploading the file, please try again!";
    }
    [/code]

    and this is the form that leads to that
    [code]
    <form enctype="multipart/form-data" action="photoparse.php" method="POST">
    <input type="hidden" name="MAX_FILE_SIZE" value="100000" />
    Choose a file to upload: <input name="uploadedfile" type="file" /><br />
    <input type="submit" value="Upload File" />
    </form>
    [/code]

    ?? i checked everything i think...

  7. I am getting this error:
    Warning: Cannot modify header information - headers already sent by (output started at db.php:14) in checkuser.php on line 39

    line 39 = mysql_query("UPDATE users...
    [code]
    if($login_check > 0){
        while($row = mysql_fetch_array($sql)){
        foreach( $row AS $key => $val ){
            $$key = stripslashes( $val );
        }
            // Register some session variables!
            session_register('first_name');
            $_SESSION['first_name'] = $first_name;
            session_register('last_name');
            $_SESSION['last_name'] = $last_name;
            session_register('email_address');
            $_SESSION['email_address'] = $email_address;
            session_register('special_user');
            $_SESSION['user_level'] = $user_level;
           
            mysql_query("UPDATE users SET last_login=now() WHERE userid='$userid'");
            header("Location: login_success.php");
        }
    [/code]
    i cant figure out what is wrong..
  8. alright, this is really starting to frustrate me... now it says "Column count doesn't match value count at row 1" when i try to register

    this is my regiser.php:

    [code]
    <?

    $first_name = $_POST['first_name'];
    $last_name = $_POST['last_name'];
    $email_address = $_POST['email_address'];
    $password = $_POST['password'];
    $repassword = $_POST['repassword'];

    $first_name = stripslashes($first_name);
    $last_name = stripslashes($last_name);
    $email_address = stripslashes($email_address);$password = stripslashes($password);
    $repassword = stripslashes($repassword);

    if((!$first_name) || (!$last_name) || (!$email_address)){
        echo 'You did not submit the following required information! <br />';
        if(!$first_name){
            echo "First Name is a required field. Please enter it below.<br />";
        }
        if(!$last_name){
            echo "Last Name is a required field. Please enter it below.<br />";
        }
        if(!$email_address){
            echo "Email Address is a required field. Please enter it below.<br />";
        }
        if(!$password==repassword){
            echo "Passwords are not the same.<br />";
        }
        include 'join_form.html';
        exit();
    }
       
    # does this user already exist in the database? lets check for that now...
    $sql_email_check = mysql_query("SELECT email_address FROM users WHERE email_address='$email_address'");


    $email_check = mysql_num_rows($sql_email_check);

        if($email_check > 0){
            echo "<strong>Your email address has already been used by another member in our database. Please use a different Email address!";
            unset($email_address);


        include 'join_form.html';
        exit();
    }


    $sql = mysql_query("INSERT INTO users (first_name, last_name, email_address, password,  signup_date, decrypted_password)
            VALUES('$first_name', '$last_name', '$email_address', '$db_password',now())") or die (mysql_error());

    if(!$sql){
        echo 'There has been an error creating your account. Please contact the webmaster.';
    } else {
        $userid = mysql_insert_id();
        // Let's mail the user!
        $subject = "Your Membership at mywebsite.com";
        $message = "Dear $first_name $last_name,
        You are now registered at our website, http://www.mywebsite.com!
       
        To activate your membership, please login here: http://www.patall8.100webspace.net/login_form.html
       
        Once you activate your membership, you will be able to login with the following information:
        Password: $password
        Please keep this username and password in a location that is easily accessible by you.
       
        Thanks!
        Pat
       
        This is an automated response, please do not reply!";
       
        mail($email_address, $subject, $message, "From:    <mr.monicaclinton@gmail.com@>\nX-Mailer: PHP/" . phpversion());
        echo 'Your membership information has been mailed to your email address! Please check it and follow the directions!';
    }
    ?>
    [/code]

    and my mySQL query contains:
    userid
    first_name
    last_name
    email_address
    password
    signup_date
    activated
    decrypted_password


    sorry for asking for so much help but ive been trying to figure it out for a couple hours now
×
×
  • 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.