Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Messages - Malkz

Pages: [1]
1
Beginners - Learning PHP / Re: Can't upload the same file twice
« on: June 01, 2012, 12:14:14 PM »
Found the problem. The delete variable returned the $_GET function needed to be cleared before the next upload. Thanks again Ojoshiro for your input. For anyone else with a similar problem the following code works.
PHP Code: [Select]

if(isset($_POST['upload']))
{
	
//clear 'delete' variable from previous delete operation
	
$_GET["delete"]=NULL;

	
$uploadDir="../gallery/";
	
$fileName $_FILES['file']['name'];

	
$tmpName $_FILES['file']['tmp_name'];
	
$fileSize $_FILES['file']['size'];
	
$fileType $_FILES['file']['type'];

	
$filePath $uploadDir $fileName;

	
$result move_uploaded_file($tmpName$filePath);
	
	
if (!
$result) {
	
	
echo 
"Error uploading file";
	
	
exit;
	
}
}

2
Beginners - Learning PHP / Re: Can't upload the same file twice
« on: May 30, 2012, 02:45:35 PM »
Thanks Ojoshiro for your response.
Sorry, I realise that I haven't made the title of this post very clear.
I upload picture "Bluehills.jpg", no problems, I then upload picture "Winter.jpg", no problems.
I upload "Bluehills.jpg" again, no problems. I delete file "Bluehills.jpg", no problems. I delete "Winter.jpg", no problems. When I upload "Bluhills.jpg" again, it uploads but with error message, "Warning: unlink(../gallery/Winter.jpg) [function.unlink]: No such file or directory in C:\wamp\www\LiquidBox\admin\add_delete_photos.php".
If I try to upload "Winter.jpg" again, I get no errors but the file doesn't upload. In the address bar the file deleted filename is still present as if it's trying to delete the file "Winter.jpg" which doesn't exist.
http://localhost/LiquidBox/admin/add_delete_photosOLD.php?var=Winter.jpg

I've tried to add the line "if ( file_exists( $uploadDir.$fileName ) )" for the delete section of code with no joy yet.
I'll keep trying...

3
Beginners - Learning PHP / Can't upload the same file twice
« on: May 29, 2012, 04:47:50 PM »
I have a php script to upload nad delete photos, which mostly works. However, if I upload a photo and then delete it, when I try to upload it again I get an error message, "Warning: unlink(../gallery/Sunset.jpg) [function.unlink]: No such file or directory in C:\wamp\www\LiquidBox\admin\add_delete_photos.php on line 30"
What am I doing wrong?

PHP Code: [Select]
<?php
//error_reporting(E_ALL ^ E_NOTICE);
$var="";
$path="";


if(isset(
$_POST['upload']))
{
$uploadDir="../gallery/";
$fileName $_FILES['file']['name'];

$tmpName $_FILES['file']['tmp_name'];
$fileSize $_FILES['file']['size'];
$fileType $_FILES['file']['type'];

$filePath $uploadDir.$fileName;

$result move_uploaded_file($tmpName$filePath);
if (!
$result) {
echo 
"Error uploading file";
exit;
}

}
if (
$_GET)
{
$var=$_GET["var"];
$path="../gallery/".$var;

unlink($path);
$path="";

}
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link rel="stylesheet" type="text/css" href="admin.css" />
<script src="admin.js" type="text/javascript"></script>
<title>Add Delete Photographs</title>

</head>

<body>
<div class="container">
	
<div class="header">
	
<h1>Admin Control Panel</h1>
	
</div>
	

	
<div class="centre">
	
<h2>Add Photos to Gallery</h2>
	
<form action="" method="post" name = "upload" onsubmit="return validate_upload ( );" enctype="multipart/form-data">
	
<table>
	
<tr><td><input type="file" name="file" id="file" /></td></tr>
	
<tr><td><input type="submit" name="upload" value="submit" /></td></tr>
	
</table>
	
</form>

	
<h2>Delete Photos from Gallery</h2>

	
<form action="" onclick="return confirm_delete()" name "delete" method="get">
	
<table>
	
<?php $count "0";
	
$getDir opendir("../gallery/");
	
while(
$filename readdir($getDir)) {
	
	
if (
$filename[0]!= "." && $filename[0]!= ".." && $filename!= "Thumbs.db") {
	
	
	
echo 
"<tr><td><a href='../gallery/".$filename."'>$filename</a></td><td>";?>
	
	
	
<a style="float:right; padding-left: 10px;"href="?var=<?php echo $filename;?>">delete</a></td></tr>
	
	
	
<?php
	
	
$count++;
	
	
}
	
	
$var="";
	

	
?>

	
</table>
	
</form>
	
</div>
</div>
</body>
</html> 

Pages: [1]