Help with some uploading codes

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Aravinthan
Forum Commoner
Posts: 84
Joined: Mon Jan 28, 2008 6:34 pm

Help with some uploading codes

Post by Aravinthan »

Hi,

I am working on a website and I need to let the users upload around 7 files and then update Mysql tables with those files.

So I did all that, but now I want it to be user-friendly, so I would like it to to show a loading message during the files gets uploaded and while the MYSQL tables are being updated.

Also, I would like to show the steps that the user has finished.

So what I did is that I created an index page with 2 iframes. The one that runs the updating code and the other showing the steps.
And when a step is done, it's supposed to set a variable as true...But I cant check if its working, as I dont know how I can refresh the other iframe... I tried the meta tag refresh, but it refreshes the whole page, making the uploading impossible....

Thanks for your help,
Ara
lcarron000
Forum Newbie
Posts: 13
Joined: Thu May 20, 2010 2:51 pm

Re: Help with some uploading codes

Post by lcarron000 »

Post your code and i will try to help you.
Aravinthan
Forum Commoner
Posts: 84
Joined: Mon Jan 28, 2008 6:34 pm

Re: Help with some uploading codes

Post by Aravinthan »

Ok thanks,

First of this is the index page:

Code: Select all

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<HTML>
<HEAD>
<TITLE></TITLE>
<META NAME="Generator" CONTENT="TextPad 4.6">
<META NAME="Author" CONTENT="?">
<META NAME="Keywords" CONTENT="?">
<META NAME="Description" CONTENT="?">
</HEAD>

<BODY BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#FF0000" VLINK="#800000" ALINK="#FF00FF" BACKGROUND="?">
<?php



echo "Admin Cpanel</br>";

?>
<iframe name="updates" src="../fichiers/form.php" width="500" height="300" />

<iframe src="lesEtapes.php" width="500" height="300" name="etapes"/>


</BODY>
</HTML>


This is the lesEtapes.php :

Code: Select all

<?php

include("../fichiers/connection.php");
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<HTML>
<HEAD>
<TITLE></TITLE>
<META NAME="Generator" CONTENT="TextPad 4.6">
<META NAME="Author" CONTENT="?">
<META NAME="Keywords" CONTENT="?">
<META NAME="Description" CONTENT="?">

</HEAD>

<BODY BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#FF0000" VLINK="#800000" ALINK="#FF00FF" BACKGROUND="?">
<?php
if($upload_result)
{
$Uimage = "<img src='../images/succes.gif' visible='true' width='25' height='25' />";
}
else
{
$Uimage = "<img src='../images/fail.png' visible='true' width='25' height='25' />";
}

if($players_result)
{
$Pimage = "<img src='../images/succes.gif' visible='true' width='25' height='25' />";
}
else
{
$Pimage = "<img src='../images/fail.png' visible='true' width='25' height='25' />";
}

if($teams_result)
{
$Timage = "<img src='../images/succes.gif' visible='true' width='25' height='25' />";
}
else
{
$Timage = "<img src='../images/fail.png' visible='true' width='25' height='25' />";
}

if($histories_result)
{
$Himage = "<img src='../images/succes.gif' visible='true' width='25' height='25' />";
}
else
{
$Himage = "<img src='../images/fail.png' visible='true' width='25' height=25' />";
}

if($statistics_result)
{
$STimage = "<img src='../images/succes.gif' visible='true' width='25' height='25' />";
}
else
{
$STimage = "<img src='../images/fail.png' visible='true' width='25' height='25' />";
}

if($draftpicks_result)
{
$Dimage = "<img src='../images/succes.gif' visible='true' width='25' height='25' />";
}
else
{
$Dimage = "<img src='../images/fail.png' visible='true' width='25' height='25' />";
}

if($league_result)
{
$Limage = "<img src='../images/succes.gif' visible='true' width='25' height='25' />";
}
else
{
$Limage = "<img src='../images/fail.png' visible='true' width='25' height='25' />";
}

if($schedule_result)
{
$SHimage = "<img src='../images/succes.gif' visible='true' width='25' height='25' />";
}
else
{
$SHimage = "<img src='../images/fail.png' visible='true' width='25' height='25' />";
}

if($details_result)
{
$ADimage = "<img src='../images/succes.gif' visible='true' width='25' height='25' />";
}
else
{
$ADimage = "<img src='../images/fail.png' visible='true' width='25' height='25' />";
}

echo "<ol>
<li>Effacer les anciens fichiers / Televerser les fichiers     $Uimage</li></br>
<li>Mettre a jour le fichier: players.ehm                    $Pimage</li></br>
<li>Mettre a jour le fichier: teams.ehm                       $Timage</li></br>
<li>Mettre a jour le fichier: histories.ehm                   $Himage</li></br>
<li>Mettre a jour le fichier: statistics.ehm                   $STimage</li></br>
<li>Mettre a jour le fichier: draftpicks.ehm                   $Dimage</li></br>
<li>Mettre a jour le fichier: league.ehm                       $Limage</li></br>
<li>Mettre a jour le fichier: schedule.ehm                     $SHimage</li></br>
<li>Ajouter les details                                        $ADimage</li></br>
</ol>";
?>

</BODY>
</HTML>
Aravinthan
Forum Commoner
Posts: 84
Joined: Mon Jan 28, 2008 6:34 pm

Re: Help with some uploading codes

Post by Aravinthan »

Form.php :

Code: Select all

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<HTML>
<HEAD>
<TITLE></TITLE>
<META NAME="Generator" CONTENT="TextPad 4.6">
<META NAME="Author" CONTENT="?">
<META NAME="Keywords" CONTENT="?">
<META NAME="Description" CONTENT="?">
</HEAD>

<BODY BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#FF0000" VLINK="#800000" ALINK="#FF00FF" BACKGROUND="?">
<form action="upload.php" ENCTYPE="multipart/form-data" method="post">
players.ehm: <input id="file1" type="file" name="file1"><br/>
teams.ehm: <input id="file2" type="file" name="file2"><br/>
statistics.ehm: <input id="file3" type="file" name="file3"><br/>
league.ehm: <input id="file4" type="file" name="file4"><br/>
schedule.ehm: <input id="file5" type="file" name="file5"><br/>
histories.ehm: <input id="file6" type="file" name="file6"><br/>
draftpicks.ehm: <input id="file7" type="file" name="file7"><br/>
<input type="submit" value="Upload!">
</form>


</BODY>
</HTML>

upload.php

Code: Select all

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<HTML>
<HEAD>
<TITLE></TITLE>
<META NAME="Generator" CONTENT="TextPad 4.6">
<META NAME="Author" CONTENT="?">
<META NAME="Keywords" CONTENT="?">
<META NAME="Description" CONTENT="?">


<BODY BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#FF0000" VLINK="#800000" ALINK="#FF00FF" BACKGROUND="?">
<?php
include("connection.php");
$directory_self = getcwd();
for($i = 1; $i < 8; $i++){
$file_name = $_FILES['file'. $i]['name'];
// strip file_name of slashes

$file_name = stripslashes($file_name);
$file_name = str_replace("'","",$file_name);
$copy = move_uploaded_file($_FILES['file'. $i]['tmp_name'],"../datas/$file_name");
 // prompt if successfully copied

 $sql = "DROP TABLE if exists `statistics`";

 mysql_query($sql) or die(mysql_error());

 $sql = "DROP TABLE if exists `teams`";

 mysql_query($sql) or die(mysql_error());

 $sql = "DROP TABLE if exists `schedule`";

 mysql_query($sql) or die(mysql_error());

 $sql = "DROP TABLE if exists `draftpicks`";

 mysql_query($sql) or die(mysql_error());

 $sql = "DROP TABLE if exists `history`";

 mysql_query($sql) or die(mysql_error());


}
if($copy){
$upload_result = true;
echo "<a href='players.php'>Commencer la mise a jour</a>";

}
else
{
echo "$directory_self<br/>";
echo "Une erreur s'est produite!</br> <a href='form.php'>Re-essayer</a>";
 }
?>

</BODY>
</HTML>
connection.php :

Code: Select all

<?php
$link = mysql_connect ("localhost", "user", "passer")or die("mysql_error()");

		mysql_select_db ("DB", $link)or die("mysql_error()");
$upload_result = false;
$players_result = false;
$teams_result = false;
$histories_result = false;
$statistics_result = false;
$draftpicks_result = false;
$league_result = false;
$schedule_result = false;
$details_result = false;
		?>
Aravinthan
Forum Commoner
Posts: 84
Joined: Mon Jan 28, 2008 6:34 pm

Re: Help with some uploading codes

Post by Aravinthan »

As you see in the upload.php,

Where I set the upload_result variable to true, well that's what I do throught the others steps after the MYSQL Insert code
lcarron000
Forum Newbie
Posts: 13
Joined: Thu May 20, 2010 2:51 pm

Re: Help with some uploading codes

Post by lcarron000 »

Try this. Change iframenamehere to the name of the iframe you wish to reload.

Code: Select all

<script type="text/javascript">
window.parent.iframenamehere.location.reload()
</script>
Aravinthan
Forum Commoner
Posts: 84
Joined: Mon Jan 28, 2008 6:34 pm

Re: Help with some uploading codes

Post by Aravinthan »

I guess, it refreshed the iframe, but the picture is still at the x... not to the check image..
lcarron000
Forum Newbie
Posts: 13
Joined: Thu May 20, 2010 2:51 pm

Re: Help with some uploading codes

Post by lcarron000 »

You can insert it this way.

Code: Select all

if ($upload_result == true) {
echo("<script type="text/javascript">
window.parent.iframename.location.reload()
</script>");
}
Should work for any iframe you need to reload. Just replace the name as needed.
lcarron000
Forum Newbie
Posts: 13
Joined: Thu May 20, 2010 2:51 pm

Re: Help with some uploading codes

Post by lcarron000 »

use echo to check the value of your variable.
Aravinthan
Forum Commoner
Posts: 84
Joined: Mon Jan 28, 2008 6:34 pm

Re: Help with some uploading codes

Post by Aravinthan »

It keeps returning false,

Making me think that the refresh isnt working...
lcarron000
Forum Newbie
Posts: 13
Joined: Thu May 20, 2010 2:51 pm

Re: Help with some uploading codes

Post by lcarron000 »

In this code i posted, for some reason i neglected to escape the double quotes in the string.
This

Code: Select all

if ($upload_result == true) {
echo("<script type="text/javascript">
window.parent.iframename.location.reload()
</script>");
}
Should be

Code: Select all

if ($upload_result == true) {
echo("<script type=\"text/javascript\">
window.parent.iframename.location.reload()
</script>");
}
Now unfortunately i jumped the gun on this. Unless $upload_result is returned false, it will continue to refresh.
You could possibly use it in upload.php like this.

Code: Select all

if($copy){
$upload_result = true;
echo "<a href='players.php'>Commencer la mise a jour</a>";
echo("<script type=\"text/javascript\">
window.parent.iframename.location.reload()
</script>");
}
I forget lots so i will remind you to change iframename to the name of the iframe you want to refresh.
You need to find out why $upload_result returns false. Only reason i see is by $copy returning false
Aravinthan
Forum Commoner
Posts: 84
Joined: Mon Jan 28, 2008 6:34 pm

Re: Help with some uploading codes

Post by Aravinthan »

Well,
I can see the echo of $copy... so it's returning true...
Aravinthan
Forum Commoner
Posts: 84
Joined: Mon Jan 28, 2008 6:34 pm

Re: Help with some uploading codes

Post by Aravinthan »

Up
Post Reply