Hey, I have a problem with renaming a file. When I rename it then instead of changing the name, it changes the name and then transfers it to the sites root directory? Here is my code.
All the variables are filled correctly. The code to them is:
<?php
if ($sleep=="N") { } else { sleep(3); }
?>
<html>
<head>
<title>Camera Utility 0.7</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="stylesheet.css" rel="stylesheet" type="text/css">
</head>
<body>
<form name="form1" method="post" action="">
<p><strong>Camera Utility 0.7</strong></p>
<table width="500" border="0" cellpadding="0" cellspacing="5" class="tabletext">
<tr bgcolor="#CCCCCC">
<td width="50%"><div align="center">Images on Camera</div>
</td>
<td width="50%"><div align="center">Images on Hard Drive</div>
</td>
</tr>
<tr>
<td width="50%" valign="top">
<?php
$dirname = "G:/DCIM/100MLT29";
$dir= opendir($dirname);
while ( false!= ($file = readdir($dir) ) )
{
if ( ($file != ".") and ( $file != "..") )
{
$dirname = "G:/DCIM/100MLT29";
$destination = "C:/Digiphotos/$file";
$path="C:/Digiphotos/";
$fullpath="$dirname/$file";
$fullpathview="G:/DCIM/100MLT29/$file";
$file_list .= "<input type='submit' class='copy' value='' onClick=\"window.open('copyutil.php?fullpath=$fullpath&destination=$destination', 'copy', config='height=100,width=200')\">";
$file_list .= "<input type='submit' class='view' value='' onClick=\"window.open('$fullpathview')\">";
$file_list .= "<input type='submit' class='cprn' value='' onClick=\"window.open('copyutil.php?fullpath=$fullpath&destination=$destination&rename=1&path=$path', 'copyrename', config='height=150,width=300')\">";
$file_list .= "<input type='submit' class='del' value='' onClick=\"window.open('delete.php?fullpath=$fullpath', 'delete', config='height=200,width=200')\">";
$file_list .= "<img src='spacer.gif' width='10' height='10' border='0'>$file<br>";
}
}
closedir($dir);
echo($file_list);
?>
</td>
<td width="50%" valign="top"><?php
$dirname = "C:/Digiphotos";
$dir= opendir($dirname);
while ( false!= ($file2 = readdir($dir) ) )
{
if ( ($file2 != ".") and ( $file2 != "..") )
{
$dirname = "C:/Digiphotos";
$fullpath="$dirname/$file2";
$file_list2 .= "<input type='submit' class='view' value='' onClick=\"window.open('$fullpath')\" >";
$file_list2 .= "<input type='submit' class='del' value='' onClick=\"window.open('delete.php?fullpath=$fullpath', 'delete', config='height=200,width=200')\">";
$file_list2 .= "<input type='submit' class='rena' value='' onClick=\"window.open('copyutil.php?fullpath=$fullpath&destination=$fullpath&rename=1&path=$path&onlyrename=1', 'copyrename', config='height=150,width=300')\">";
$file_list2 .= "<img src='spacer.gif' width='10' height='10' border='0'>$file2<br>";
}
}
closedir($dir);
echo($file_list2);
?>
</td>
</tr>
</table>
<div align="left"></div>
<hr align="left" width="550">
<table width="302" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="31"><input name="button" type='button' class='copy' value=''>
</td>
<td width="271">Transfer Image to Hard Drive</td>
</tr>
<tr>
<td><input name="button2" type='button' class='view' value=''>
</td>
<td>View Image</td>
</tr>
<tr>
<td><input name="button2" type='button' class='cprn' value=''>
</td>
<td>Rename & Transfer Image to Hard Drive</td>
</tr>
<tr>
<td><input name="button2" type='button' class='del' value=''>
</td>
<td>Delete File</td>
</tr>
<tr>
<td><input name="button2" type='button' class='rena' value=''>
</td>
<td>Rename</td>
</tr>
</table>
<hr align="left" width="550">
<input name="button" type="submit" id="button" value="Refresh Page" onClick="location.href='digituil.php?sleep=N'" >
</form>
<p><?php echo(time()); ?></p>
</body>
</html>
<html>
<head>
<title>Copy File</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<?php
if ($rename==1)
{
if ($newname!=NULL)
{
$fullpath="$path$newname";
if (substr( $fullpath, -4 )!=".jpg") { $fullpath .= ".jpg"; }
if (rename($destination,$fullpath)) { print "<script> alert('Rename Completed Sucessfully, Please Refresh the Page'); self.close(); </script>"; } else { print "<script> alert('Rename Failed'); self.close(); </script>"; }
}
else
{
if ($onlyrename!=1) { if ( copy("$fullpath","$destination") ) { print "Transfer Completed Sucessfully !"; print "<script> alert('Transfer Completed Sucessfully') </script>"; } else { print "<script> alert('Transfer Failed') </script>"; } }
print "<br><br>";
print "Please enter the new filename for: $destination";
print "<form action='$PHP_SELF'>";
print "<input type='hidden' name='destination' value='$destination'>";
print "<input type='hidden' name='path' value='$path'>";
print "<input type='hidden' name='rename' value='1'>";
print "<input type='textbox' name='newname' width='20'><br><br>";
print "<input type='submit' value='Rename'>";
print "</form>";
}
}
else
{
sleep(2);
if ( copy("$fullpath","$destination") ) { print "Transfer completed sucessfully"; }
print "<script>";
print "alert('Transfer Completed Sucessfully');";
print "self.close();";
print "</script>";
}
?>
</body>
</html>
Sorry its so long 🙁
Thanks in advance.
Jack!
P.S I'm thinking of making functions for everything. This will make it a lot clearer, but I need to get it working again first :rolleyes: