Solved

I don't think it can be done but i want to ask you all.....

Posted on 2011-03-08
7
221 Views
Last Modified: 2012-05-11
They other day you guess helped me with this php load display a lot of images and have a button the edits the file name. Well it works great one thing is i have over 500 image loaded on the page there small 20k files that fine.

But when i use scrolls down fines a image and renames it by clicking on the edit button the page will reload at the top. So the user has to scroll back down and find where they left off.

Is there any way to fixes this so when they click edit it doesn't reset the page at the top but do it from where they left off?
<p><h1>  
All you have to do if you know the person is type their full name, click edit then move on to the next user. Thank you! 
<p></h1>

<?php 




echo '<table><tr><td>'; 

     $username = $_SESSION['user']; 
        $url = $username."./"; 
        $handle = opendir ($url); 
        while (false !== ($file = readdir($handle))) { 
            if($file != "." && $file != ".." && $file != basename(__FILE__)) {                    
                                                        
                                                             
                   echo"<form method=\"post\" action=\"data2file.php\">";
                   echo '<img border=1 src="'.$file.'">'; 
                   echo '<br />'; 
                   
                   echo "Enter new name: <input type='text' name='new-name' length='30'>
                   <textarea type=text size='1' height='1'style='display:none' name='file-name' >".$file."</textarea>"; 
                  
                    
                   echo "<input type=submit name=\"$file\" value=Edit>" ; 
                   print $file; 
                   echo '<br>'; 
                   echo '<hr>'; 
                   echo "</form>";
            
            } 
        } 
echo '</td>'; 

echo ' 

</table>'; 
 
?> 


here is the data2file.php


<html>
<body>

<script type="text/javascript"><!--
setTimeout('Redirect()',1000);
function Redirect()
{
  location.href = 'http://laptop-vm/IDbag/edit.php';
}
// --></script>

<?php 
echo $_POST['new-name'];
echo '<br>';
echo $_POST['file-name']; 



rename($_POST['file-name'], $_POST['new-name'].".jpg");


if (copy("C:/server/xampp/htdocs/IDbag/" .$_POST['new-name'].".jpg","C:/server/xampp/htdocs/IDbag/done/".$_POST['new-name'].".jpg")) {
  unlink($_POST['new-name'].".jpg");
}


echo '<br>';
echo "Successfully!"; 
?>



</body>
</html>

Open in new window

0
Comment
Question by:mikearmas
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 3

Expert Comment

by:Duboux
ID: 35071808
Add an anchor before each image, and if u were using the same page for renaming as for showing like I suggested in there, u could even do a <form action="page.php#photo_number">

Example piece in HTML:

<a id="photo_30">
<form action="pictures.php#photo_30" method="post">
...photo...
<input type="hidden" name="name_orig" value="photo_name" />
<input type="text" name="name_new" value="Add new name here" />
<input type="submit" value="change">
</form>

U see I use photo_30 to reference to that photo. Because u can't use the current photo name, in case u're changing it anyway.
So in your php-loop that shows the photo, just add an increasing number in it.

loop {
      echo "<a id=\"photo_".$id."\">";
      $id++
}
0
 

Author Comment

by:mikearmas
ID: 35085238
ok that helped thank you i got it to loop the id # to each image. if i view the sorce code of the page it does it right

<form method=\"post\" action=\"data2file.php#photo_"1\"><a id=\"photo_"1"\"><img border=1 src="-1033918356.JPG"></a><br />Enter new name: <input type='text' name='new-name' length='30>

thats from the source code so it"a right but when i click it this is what i get in the address bar. and a error on the page

http://laptop-vm/IDbag/%5C%22data2file.php?new-name=44532234563&file-name=test.jpg&test.jpg=Edit#photo_%22556\%22
<p><h1>
All you have to do if you know the person is type their full name, click edit then move on to the next user. Thank you!
<p></h1>

<?php


$id = 1;

echo '<table><tr><td>';

     $username = $_SESSION['user'];
        $url = $username."./";
        $handle = opendir ($url);
        while (false !== ($file = readdir($handle))) {
            if($file != "." && $file != ".." && $file != basename(__FILE__)) {


                   echo'<form method=\"post\" action=\"data2file.php#photo_'.$id.'\">';
                   echo '<a id=\"photo_"'.$id.'"\"><img border=1 src="'.$file.'"></a>';
				   $id++;
                   echo '<br />';

                   echo "Enter new name: <input type='text' name='new-name' length='30'>
                   <textarea type=text size='1' height='1'style='display:none' name='file-name' >".$file."</textarea>";


                   echo "<input type=submit name=\"$file\" value=Edit>" ;
                   print $file;
                   echo '<br>';
                   echo '<hr>';
                   echo "</form>";

            }
        }
echo '</td>';

echo '

</table>';

?>

Open in new window

0
 
LVL 3

Expert Comment

by:Duboux
ID: 35107051
<form method=\"post\" action=\"data2file.php#photo_"1\"><a id=\"photo_"1"\"><img border=1 src="-1033918356.JPG"></a><br />Enter new name: <input type='text' name='new-name' length='30>
That doesn't look that good.
if that is source code / a.k.a. HTML then those \ shouldn't be in there at all ;)
I see u type differently than I do. u use ' to echo. In that case u don't need \" but can just use " in there ;)

Also <a id=\"photo_"1"\"> should be <a id="photo_1">
But I don't see that in the php code u showed beneath that.


So what u need to do is remove all the \ from the code I gave u ;)
if you echo with single '

I see u also sometimes echo with " in that case u either need to leave the \ in there, or also echo with just single '

Dit u follow that ? lol
0
WordPress Tutorial 1: Installation & Setup

WordPress is a very popular option for running your web site and can be used to get your content online quickly for the world to see. This guide will walk you through installing the WordPress server software and the initial setup process.

 
LVL 3

Expert Comment

by:Duboux
ID: 35107089
okay, just copy/paste this part, lol:

                   echo'<form method="post" action="data2file.php#photo_'.$id.'">';
                   echo '<a id="photo_'.$id.'"><img border="1" src="'.$file.'"></a>';
                   echo '<br />';
                   echo 'Enter new name: <input type="text" name="new-name" length="30">
                   <textarea type="text" size="1" height="1" style="display: none;" name="file-name">'.$file.'</textarea>';


                   echo '<input type="submit" name="'.$file.'" value="Edit">';
                   print $file;
                   echo '<br>';
                   echo '<hr>';
                   echo '</form>';
                   $id++;

Open in new window

0
 

Author Comment

by:mikearmas
ID: 35109734
yep that worked i didn't get any errors but this is the data2file.php that has a redirect in the code to reload the edit.php page and it's doesn't know about the photo_id #. How can i have to remember it ?
<html>
<body>

<script type="text/javascript"><!--
setTimeout('Redirect()',1000);
function Redirect()
{
  location.href = 'http://laptop-vm/IDbag/edit.php';
}
// --></script>

<?php
echo $_POST['new-name'];
echo '<br>';
echo $_POST['file-name'];



rename($_POST['file-name'], $_POST['new-name'].".jpg");


if (copy("C:/server/xampp/htdocs/IDbag/" .$_POST['new-name'].".jpg","C:/server/xampp/htdocs/IDbag/done/".$_POST['new-name'].".jpg")) {
  unlink($_POST['new-name'].".jpg");
}


echo '<br>';
echo "Successfully!";
?>



</body>
</html>

Open in new window

0
 
LVL 3

Accepted Solution

by:
Duboux earned 500 total points
ID: 35118256
Okay, I couldn't find a way in PHP to read the anchor that was sent with in the url.
Seems like it's a clientside value..

So my idea won't work on your 2 pages method.


So... solutions..

1) just take those few lines of code from the 2nd page and paste it into the 1st page and it'll work.


2) in the 2nd page, u know the new name. If you forward this to your 1st page, it'll be fine !
change the javascript function to:
function Redirect()
{
  location.href = 'http://laptop-vm/IDbag/edit.php#<?= $_POST['new-name'].".jpg" ?>';
}
and place it below the php-code

Then in your 1st page, you must adjust your anchors to the filenames.
0
 

Author Closing Comment

by:mikearmas
ID: 35150677
thank you
0

Featured Post

Are You Using the Best Web Development Editor?

The worlds of web hosting and web development are constantly evolving. Every year we see design trends change, coding standards adapt and new frameworks/CMS created. With such a quick pace of change it’s easy to get lost trying to keep up.

See if your editor made the list.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question