*****Dynamic PHP w/ Upload*****

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
zylkaa
Forum Newbie
Posts: 8
Joined: Mon Mar 23, 2009 7:32 pm
Location: Places

*****Dynamic PHP w/ Upload*****

Post by zylkaa »

I need to use PHP to create a link on the page. I want to use the upload code (below) to create a link to a page where the file can be deleted, or so on.

Upload code:

Code: Select all

<?php 
$target = "public/"; 
$target = $target . basename( $_FILES['uploaded']['name']) ; 
$ok=1; 
if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)) 
{
echo "The file has been uploaded <a href='http://www.filefetchers.co.cc/[color=#FF0000]$target[/color]'>here</a>.";
} 
else {
echo "Sorry, there was a problem uploading your file.";
}
?>

You can see that I tried to do this (in red). This works, but I want the link to create a PHP page and not just use this link. The link would work, but I need to create a page that inputs the uploaded file name, and creates a page with a delete button or something. I don't know if you can use the Get function, or what, but this is important. PLEASE HELP!!!
If you don't understand what I want, PM me!
tech603
Forum Commoner
Posts: 84
Joined: Thu Mar 19, 2009 12:27 am

Re: *****Dynamic PHP w/ Upload*****

Post by tech603 »

I would suggest creating a database to store the image name and image location. This way you can create a page that lists all images and allows for editing/deleting the image, image name and locations.

Then you can do something like this:
create a database table called userImages and create three columns an id, imageName, imageLocation
create a page called imageList.php
$result = mysql_query(Select id, imageName, imageLocation From userImages);
while(list($id, $imageName, $imageLocation) = mysql_fetch_array($result))
{
echo "<tr><td>" . $id . "</td><td>" . $imageName . "</td><td>" . $imageLocation . "</td><td><a href='imageEdit.php?id=" . $id . "' >Delete</a></tr>";
}
Then create a page where you will delete or edit.

Code: Select all

 
if(isset($_GET['id']))
{
$id = $_GET['id'];
}
 
$result = mysql_query("Select id, imageName, imageLocation From userImages Where id='$id' ");
while(list($id, $imageName, $imageLocation) = mysql_fetch_array($result))
{
echo '<form action="imageEdit.php" action="post">
        <input type="text" name="imageName" value="' . $imageName .'" size="25"><br />
        <input type="text" name="imageLocation" value="' . $imageLocation . '" size="25"><br />
        <input type="submit" name="edit" value="Edit"><br />
        <input type="submit" name="delete" value="Delete">';
}
 
// Then on submit check for whether or not you want to edit or delete
 
if(isset($_POST['edit']))
{
//create edit db scrtip ect...
} 
elseif(isset($_POST['delete']))
{
//create delete db script
}
else
{
echo "your error message";
}
 
Hope that helps point you in the right direction.
zylkaa
Forum Newbie
Posts: 8
Joined: Mon Mar 23, 2009 7:32 pm
Location: Places

*****Not Neccessarily Dynamic PHP w/ Upload*****

Post by zylkaa »

I am not using images. I am going to upload files and I want a permanent link to a delete or edit page. I am new to MySql, but not PHP, and I have no idea what I'm doing. Can you make this a little easier to understand and simpler? I want to create a page called $id_admin.php or something and make it a permanent page so the uploader can delete or edit the file when they want to.




DO I NEED THIS CODE??

I have this code so far for edit.php:

Code: Select all

<?php
if(isset($_GET['id']))
{
$id = $_GET['id'];
}
 
$result = mysql_query("Select id, Name, Location From pub_f Where id='$id' ");
while(list($id, $Name, $Location) = mysql_fetch_array($result))
{
echo '<form action="edit.php" action="post">
        <input type="text" name="Name" value="' . $Name .'" size="25"><br />
        <input type="text" name="Location" value="' . $Location . '" size="25"><br />
        <input type="submit" name="edit" value="Edit"><br />
        <input type="submit" name="delete" value="Delete">';
}
 
// Then on submit check for whether or not you want to edit or delete
 
if(isset($_POST['edit']))
{
//create edit db scrtip ect...
}
elseif(isset($_POST['delete']))
{
//create delete db script
}
else
{
echo "your error message";
}
?>
and this for page.php:

Code: Select all

<?php
 
mysql_connect("mysql7.000webhost.com", "username", "password") or die(mysql_error());
echo " ";
mysql_select_db("uFiles") or die(mysql_error());
echo " ";
 
$result = mysql_query("Select id, Name, Location From pub_f");
while(list($id, $Name, $Location) = mysql_fetch_array($result))
{
echo "<tr><td>" . $id . "</td><td>" . $Name . "</td><td>" . $Location . "</td><td><a href='edit.php?id=" . $id . "' >Edit or Delete</a></tr>";
}
?>
I have this code for upload.php:

Code: Select all

<?php 
$target = "public/"; 
$target = $target . basename( $_FILES['uploaded']['name']) ; 
$ok=1; 
if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)) 
{
echo "The file has been uploaded <a href='http://www.filefetchers.co.cc/$target'>here</a>.";
} 
else {
echo "Sorry, there was a problem uploading your file.";
}
?>
and this for uploader.php:

Code: Select all

        <form enctype="multipart/form-data" action="upload.php" method="POST">
Please choose a file: <input name="uploaded" type="file" /><br />
<input type="submit" value="Upload" />
</form>
I want to upload a file and see a link on my screen saying that:
Your file has been uploaded to: "http://www.someplace.com/public/filename.ext". Edit or Delete your file here: "http://www.someplace.com/public/filename_admin.php
Post Reply