Link to home
Create AccountLog in
JavaScript

JavaScript

--

Questions

--

Followers

Top Experts

Avatar of Nathan Riley
Nathan Riley๐Ÿ‡บ๐Ÿ‡ธ

Remove C:\fakepath
The current javascript code below is for my upload of a users avatar. ย When the user hits browse and selects and image in the form box it then shows:

C:\fakepath\imagename.jpg

I want to remove the C:\fakepath\ from there. ย I don't know javascript so was hoping it was an easy fix in my below code that's used.

// <![CDATA[
$(document).ready(function () {
    $('input[type=file]').each(function () {
        var label = 'Browse';
        var button = '<input type="button" class="button-alt" value="' + label + '" />';
        $(this).wrap('<div class="fileinput"></div>');
        $(this).addClass('file').css('opacity', 0); //set to invisible
        $(this).parent().append($('<div class="filemask" />').append($('<input type="text" class="inputbox-sml" size="40" style="margin-right:10px"/>').attr('id', $(this).attr('id') + '__fake')).append(button));

        $(this).bind('change', function () {
            $('#' + $(this).attr('id') + '__fake').val($(this).val());;
        });
        $(this).bind('mouseout', function () {
            $('#' + $(this).attr('id') + '__fake').val($(this).val());;
        });
    });
});
// ]]>

Open in new window

Zero AI Policy

We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.


Avatar of mankowitzmankowitz๐Ÿ‡บ๐Ÿ‡ธ

Try this
function basename(path) {
    return path.replace(/\\/g,'/').replace( /.*\//, '' );
}

Open in new window


which I ruthlessly stole from http://planetozh.com/blog/2008/04/javascript-basename-and-dirname/

Avatar of Nathan RileyNathan Riley๐Ÿ‡บ๐Ÿ‡ธ

ASKER

where would I place that in my above code?

SOLUTION
Avatar of mankowitzmankowitz๐Ÿ‡บ๐Ÿ‡ธ

Link to home
membership
Log in or create a free account to see answer.
Signing up is free and takes 30 seconds. No credit card required.
Create Account

Avatar of Nathan RileyNathan Riley๐Ÿ‡บ๐Ÿ‡ธ

ASKER

You need the entire page?

<?php
  /**
   * Account Profile
   *
   * @package Advanced Login System
   * @author wojoscripts.com
   * @copyright 2010
   * @version $Id: account.php, v2.00 2011-07-10 10:12:05 gewa Exp $
   */
	  
  $row = $user->getUserData();
?>
<?php include("headerfront.php");?>


    <p class="info">Here you can make changes to your profile...</p>
    <div class="box1" style="width:610px;">
      <form action="" method="post" id="admin_form" name="admin_form" enctype="multipart/form-data">
        <table width="100%" border="0" cellpadding="3" cellspacing="0" class="display">
          <thead>
            <tr>
              <th colspan="2" class="left">Edit Your Account</th>
            </tr>
          </thead>
          <tr>
            <th width="180"><strong>Username:</strong></th>
            <td><input name="username" type="text" disabled="disabled" class="inputbox" value="<?php echo $row['username'];?>" size="45" /></td>
          </tr>
          <tr>
            <th><strong>Password:</strong></th>
            <td><input name="password" type="password"  class="inputbox" size="45" />
              &nbsp;&nbsp; <?php echo tooltip('Leave it empty unless changing the password');?></td>
          </tr>
          <tr>
            <th><strong>Email Address: <?php echo required();?></strong></th>
            <td><input name="email" type="text" class="inputbox" value="<?php echo $row['email'];?>" size="45" maxlength="40" /></td>
          </tr>
          <tr>
            <th><strong>First Name:</strong> <?php echo required();?></th>
            <td><input name="fname" type="text" class="inputbox" value="<?php echo $row['fname'];?>" size="45" /></td>
          </tr>
          <tr>
            <th><strong>Last Name:</strong> <?php echo required();?></th>
            <td><input name="lname" type="text" class="inputbox" value="<?php echo $row['lname'];?>" size="45" /></td>
          </tr>
          <tr>
            <th><strong>Avatar:</strong></th>
            <td><input name="avatar" id="imgfile" type="file" size="40" class="inputbox" /></br> <?php echo ($row['avatar']) ? '<img src="'.UPLOADURL . $row['avatar'].'" alt=""/>' : '<img src="'.UPLOADURL.'blank.png" alt=""/>';?></td>
          </tr>
          <tr>
            <th><strong>Date Registered:</strong></th>
            <td><span class="input-out"><?php echo $row['cdate'];?></span></td>
          </tr>
          <tr>
            <th><strong>Last Login:</strong></th>
            <td><span class="input-out"><?php echo $row['ldate'];?></span></td>
          </tr>
          <tr>
            <td colspan="2"><input name="doupdate" type="submit" value="Update Profile"  class="button"/></td>
          </tr>
        </table>
      </form>
    </div>
	</div>
<script type="text/javascript">
// <![CDATA[
$(document).ready(function () {
    $('input[type=file]').each(function () {
        var label = 'Browse';
        var button = '<input type="button" class="button-alt" value="' + label + '" />';
        $(this).wrap('<div class="fileinput"></div>');
        $(this).addClass('file').css('opacity', 0); //set to invisible
        $(this).parent().append($('<div class="filemask" />').append($('<input type="text" class="inputbox-sml" size="40" style="margin-right:10px"/>').attr('id', $(this).attr('id') + '__fake')).append(button));

        $(this).bind('change', function () {
            $('#' + $(this).attr('id') + '__fake').val($(this).val());;
        });
        $(this).bind('mouseout', function () {
            $('#' + $(this).attr('id') + '__fake').val($(this).val());;
        });
    });
});
// ]]>
</script>
<?php echo $core->doForm("processUser","ajax/controller.php");?>	
</html>

Open in new window


Reward 1Reward 2Reward 3Reward 4Reward 5Reward 6

EARN REWARDS FOR ASKING, ANSWERING, AND MORE.

Earn free swag for participating on the platform.


Avatar of mankowitzmankowitz๐Ÿ‡บ๐Ÿ‡ธ

this is a bit more confusing, as you are uploading the file with a php interface that I'm not familiar with. You may be able to change the name of the avatar from within PHP. I don't think you want to change it before you upload, as your computer won't be able to find it.

Avatar of Nathan RileyNathan Riley๐Ÿ‡บ๐Ÿ‡ธ

ASKER

When I click to browse for the image and click on one to use it then places the fakepath in the form:
http://s10.postimg.org/6rvak1195/image.png

Then you hit update profile and it uploads and saves the new avatar.

I want to just hide the C:\fakepath\.

Avatar of mankowitzmankowitz๐Ÿ‡บ๐Ÿ‡ธ

right. I don't think you can do what you want using the normal file upload. In other words, that path name is how the browser knows what file it will upload. If you change it, the browser won't be able to upload, at least as I understand file upload. Once you have the file stored in your database, you can modify the filename as much as you want because (ideally) the database has a stored copy.

Free T-shirt

Get a FREE t-shirt when you ask your first question.

We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.


Avatar of Nathan RileyNathan Riley๐Ÿ‡บ๐Ÿ‡ธ

ASKER

Well ended up getting it to work, I had to remove what I guessed was the issue, turns out it was.

Here is the modified code.
// <![CDATA[
$(document).ready(function () {
    $('input[type=file]').each(function () {
        var label = 'Browse';
        var button = '<input type="button" class="button-alt" value="' + label + '" />';
        $(this).wrap('<div class="fileinput"></div>');
        $(this).addClass('file').css('opacity', 0); //set to invisible
        $(this).parent().append($('<div class="filemask" />').append($('<input type="text" class="inputbox-sml" size="40" style="margin-right:10px"/>').append(button));

        $(this).bind('change', function () {
            $('#' + $(this).attr('id') + '__fake').val($(this).val());;
        });
        $(this).bind('mouseout', function () {
            $('#' + $(this).attr('id') + '__fake').val($(this).val());;
        });
    });
});
// ]]>

Open in new window


Avatar of mankowitzmankowitz๐Ÿ‡บ๐Ÿ‡ธ

sorry, I don't see it. What did you change? You modified the ID of the button, but how does that address the path?

Do the change and mouseout bindings still work?

ASKER CERTIFIED SOLUTION
Avatar of Nathan RileyNathan Riley๐Ÿ‡บ๐Ÿ‡ธ

ASKER

Link to home
membership
Log in or create a free account to see answer.
Signing up is free and takes 30 seconds. No credit card required.

Avatar of Nathan RileyNathan Riley๐Ÿ‡บ๐Ÿ‡ธ

ASKER

My solutions worked, but points to you for your time.

Reward 1Reward 2Reward 3Reward 4Reward 5Reward 6

EARN REWARDS FOR ASKING, ANSWERING, AND MORE.

Earn free swag for participating on the platform.

JavaScript

JavaScript

--

Questions

--

Followers

Top Experts

JavaScript is a dynamic, object-based language commonly used for client-side scripting in web browsers. Recently, server side JavaScript frameworks have also emerged. JavaScript runs on nearly every operating system and in almost every mainstream web browser.