Hi, I have developed a script to upload and download files using php. I am trying to create a way to assign an ID to each file that is uploaded and downloaded. I have tried a few methods, but I believe I am missing some parts of coding: Here is the source codes for each file:
source form that user defines file and title
upload1.phpCode:<form enctype="multipart/form-data" action="upload1.php" method="POST"> Title of Article<br /> <input name="titlea" id="titlea" maxlength="356" type="text" size="55"/><br /> Upload Completed Article: <br /><input name="file" type="file" /><br /> <input type="submit" value="Upload" /> </form>
view.php // the results that should include the delete functionCode:<?php $uploaddir = "upload1/"; if(is_uploaded_file($_FILES['file']['tmp_name'])) { move_uploaded_file($_FILES['file']['tmp_name'],$uploaddir.'/'.$_FILES['file']['name']); } echo "Your file has been uploaded successfully! Yay!"; // hidden db info mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); $titlea=$_POST['titlea']; // auto_increment id should be auto generated at this point ['id'] $sql1="INSERT INTO $tbl_name(titlea)VALUES('$titlea')"; $result1=mysql_query($sql1); if($result1){ echo "name and ID generated"; } else { echo "ERROR with sql"; } mysql_close(); ?>
delupload.php // i need a way for the file to be assigned to an ID from the SQL table i have with an id [auto_increment]Code:<?php $dir = "../cw/upload1/"; $c=-1; if($handle = opendir($dir)) { while($file = readdir($handle)) { clearstatcache(); if(is_file($dir.'/'.$file)) echo ' <table><tr> <td>'.$c.'</td> <td>' '<a href="upload1/'.$file.'">'.$file.'</a>' . '</td> <td><a href="delupload.php" target="test">x</a></td> </tr> </table>'; $c++; } closedir($handle); } ?>
Code:<script type="text/javascript"> setTimeout('Redirect()',4000); function Redirect() { parent.location.href = 'newindex.php'; } </script> <?php $myFile = "$file"; unlink($myFile); echo "<script>Redirect();</script>"; ?>
The id and title and file and viewer are all working like a charm. I would simply want them to have an ID associated with them so I can deleted a specific file from the list that comes out. If you need a working demo, let me know.



Reply With Quote
Bookmarks