Jump to content

Recommended Posts

Hey guys, first post and I've just returned to PHP after about 4 years of no coding, so be gentle!  :wtf:

 

In a nutshell I'm creating a photo album and I've pretty much got the majority of it complete, apart from a few tweaks and the obvious ongoing development.

 

I'm at the stage now where I need to moderate images being uploaded, so I've made an admin only script which displays the uploaded images with links that say approve and delete.

 

Uploaded images are stored in uploads/ which are left there until i move them to img/, plus the filename is stored in mysql so I can "<img src='../uploads/".$row['filename']."' width='200'>".

 

Now, I would like to make the Approve button move the image from uploads/ to img/ and I'd like the delete button to remove both the entry from MySQL and the file from the uploads folder and I'm not too sure on how to make it work.

 

Here's what I have so far in the mod.php file (mod for moderation)

 

$image = mysql_query("SELECT * FROM images WHERE id");
while($row = mysql_fetch_assoc($image))
{
echo "
<table>
<td>
<tr>
<img src='../uploads/".$row['filename']."' width='200'><br />
</tr>
</td>
<td>
<tr>
<a href=''>Approve</a> <a href=''>Delete</a>
</tr>
</td>
</table>
";
}

 

You'll have to ignore the table tags, I'm still getting used to positioning items on the screen lol.

 

Any clues would be greatly appreciated

 

Live long and prosper.

Link to comment
https://forums.phpfreaks.com/topic/230137-deleting-data-from-a-file-mysql/
Share on other sites

http://webxadmin.free.fr/article/php-move-file-211.php

 

However, really no need to move the images; just add a field  to the db table, a field that is 0 or 1; 0 means the image is awaiting 'approval' so don't display to 'public',  1 means the image has been 'approved'. all the images can be in the same folder

Okay excellent, i've managed to get both the file and the mysql entry to delete, now for approving I was thinking of using UPDATE, but I'm wondering how I do so in such a way that a single image would have a value changed in mysql rather than them all.

 

I've tried the following but it doesn't work, any ideas?

 

$appfile=$_GET['filename'];
$sql = mysql_query("UPDATE images WHERE filename='$appfile' SET approved='1'");

if ($sql)
{	
echo "Approved!";
echo "<br />";
echo "<a href='mod.php'>Back</a>";
}
else
{
echo "Error.";
echo "<br />";
echo "<a href='mod.php'>Back</a>";
}

1. echo $appfile to be sure it contains the value you expect.

 

IF it does have the correct value

change this...

$sql = mysql_query("UPDATE images WHERE filename='$appfile' SET approved='1'");

to this...

$sql = mysql_query("UPDATE images SET approved=1 WHERE filename='$appfile'");

Thank you ever so much litebearer, you've been a great help.

 

The final thing I'm struggling with now is displaying the images that have an approved value of 1 instead of 0

 

I thought I was being clever by using an if statement, but that just basically said

 

 

if approved equals 1, then display everything

 

 

So i need to rethink it

 

 

		//Display data
	$get = mysql_query("SELECT * FROM images LIMIT $start, $per_page");
	$approved = mysql_query("SELECT * FROM images WHERE approved");
	$fetchapproved = mysql_fetch_assoc($approved);
	while($row = mysql_fetch_assoc($get))
	{
		// get data
		$filename = $row['filename'];

		echo "<div align='center'><img src='../uploads/".$filename."' / width='600px'></div>";
	}

try...

$result = mysql_query("SELECT filename FROM images WHERE approved=1");
while($row = mysql_fetch_array($result)) {
?><div align='center'><img src='../uploads/<?PHP echo $row['filename']; ?>' width='600px'></div><?PHP
}

That sort of works, it only displays the images with approved set to 1, however you can still navigate for the images it doesn't display...I think I might do it the way I originally thought and move the file to a different folder, it'll probably be simpler lol

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.