PRodgers4284 Posted March 11, 2008 Share Posted March 11, 2008 I have a script that allows file uploads to a file directory, i want the a user to be able to edit the file. The file upload works fine for adding a file but im having difficulty with the edit file upload, i clears the file upload file when i try to edit the record. Can anyone please help me with this? My code is: <?php $username = $_GET['username']; $id = $_GET['id']; if (isset($_POST['submit'])) { $error_stat = 0; $filesize_message = ''; $filetype_message = ''; if( $_FILES['userfile']['size'] > 2000000 ){ //Set the error_stat to 1, which means that an error has occurred $error_stat = 1; $filesize_message = '*Filesize too large *'; } $fileTypes = array("application/pdf", "application/msword", ""); if( !in_array("{$_FILES['userfile']['type']}", $fileTypes) ){ $error_stat = 1; $filetype_message = '*Filetype not allowed *'; } } $uploadDir = 'applicationforms/'; if (isset($_POST['submit']) && $error_stat == 0) { $fileName = $_FILES['userfile']['name']; $tmpName = $_FILES['userfile']['tmp_name']; $fileSize = $_FILES['userfile']['size']; $fileType = $_FILES['userfile']['type']; // the files will be saved in filePath $filePath = $uploadDir . $fileName; // move the files to the specified directory // if the upload directory is not writable or // something else went wrong $result will be false $result = move_uploaded_file($tmpName, $filePath); include("database.php"); if(!get_magic_quotes_gpc()) { $fileName = addslashes($fileName); $filePath = addslashes($filePath); } mysql_query("UPDATE job SET name='$fileName', type='$fileType', size='$fileSize', path='$filePath' WHERE username='$username' AND id='$id'"); ?> <br /> <a href="index.php">Back to main page</a> <br /> <br /> <br /> The Job record has been successfully updated. <?php } else { $account = mysql_fetch_array(mysql_query("SELECT * FROM job WHERE username='$username' AND id='$id'")); ?> <form method="post" class="addform" action="" enctype="multipart/fom-data"> <fieldset> <p align="right"> <a href="editjobhelp.htm" onclick="NewWindow(this.href,'name','640','260','yes');return false"><font face="Verdana" size="2">Help/Assistance</a></p> </font> </fieldset> <fieldset> <label for="cvtitle">Edit Job Application Form</label><fieldset> <p align="right"> </p> </fieldset> <label for="username">Username:</label> <input readonly name="username" type="text" id="username" value="<?php echo $_SESSION["username"]; ?>" /><br /> </fieldset> <hr class="hr_blue"/> <fieldset> <p><label for="skills">Upload Application Form</label> <input type="hidden" name="MAX_FILE_SIZE" value="2000000"><input name="userfile" type="file" class="box" id="userfile"> <span class="redboldtxt"><?php echo "$filesize_message";?></span> <span class="redboldtxt"><?php echo "$filetype_message";?></span> </p> </fieldset> <p></p> <fieldset> <p class="submit"><input type="submit" name="submit" value="EditJob" /> </fieldset> </form> <?php } ?> Link to comment https://forums.phpfreaks.com/topic/95593-edit-file-upload-help/ Share on other sites More sharing options...
PRodgers4284 Posted March 11, 2008 Author Share Posted March 11, 2008 I have the edit file upload working in another form, i cant were the difference is except for the query. The code for this form is: <?php if (isset($_POST['submit'])) { $error_stat = 0; $filesize_message = ''; $filetype_message = ''; if( $_FILES['userfile']['size'] > 2000000 ){ //Set the error_stat to 1, which means that an error has occurred $error_stat = 1; $filesize_message = '*Filesize too large *'; } $fileTypes = array("application/pdf", "application/msword", ""); if( !in_array("{$_FILES['userfile']['type']}", $fileTypes) ){ $error_stat = 1; $filetype_message = '*Filetype not allowed *'; } } $uploadDir = 'upload/'; if (isset($_POST['submit']) && $error_stat == 0) { $fileName = $_FILES['userfile']['name']; $tmpName = $_FILES['userfile']['tmp_name']; $fileSize = $_FILES['userfile']['size']; $fileType = $_FILES['userfile']['type']; // the files will be saved in filePath $filePath = $uploadDir . $fileName; // move the files to the specified directory // if the upload directory is not writable or // something else went wrong $result will be false $result = move_uploaded_file($tmpName, $filePath); include("database.php"); if(!get_magic_quotes_gpc()) { $fileName = addslashes($fileName); $filePath = addslashes($filePath); } mysql_query("UPDATE users SET username='" . $_POST["username"] . "', name='$fileName', type='$fileType', size='$fileSize', path='$filePath' WHERE username='" . $_SESSION["username"] . "'"); ?> <br /> <a href="index.php">Back to main page</a> <br /> <br /> <br /> You have successfully updated the your CV file . <?php } else { $account = mysql_fetch_array(mysql_query("SELECT * FROM users WHERE username='" . $_SESSION["username"] . "'")); ?> <form method="post" class="cvform" action="" enctype="multipart/form-data"> <fieldset> <p align="right"> <a href="cvhelp.htm" onclick="NewWindow(this.href,'name','640','240','yes');return false"><font face="Verdana" size="2">Help/Assistance</a></p> </font> </fieldset> <fieldset> <label for="cvtitle">Add/Edit CV File</label><fieldset> </fieldset> <fieldset> <label for="username">Username:</label> <input readonly name="username" type="text" id="username" value="<?php echo $_SESSION["username"]; ?>" /><br /> </fieldset> <p></p> <fieldset> <p></p> </fieldset><fieldset> <label for="skills">Upload CV</label> <input type="hidden" name="MAX_FILE_SIZE" value="2000000"><input name="userfile" type="file" class="box" id="userfile"> <span class="redboldtxt"><?php echo "$filesize_message";?></span> <span class="redboldtxt"><?php echo "$filetype_message";?></span> </fieldset> <fieldset> <p class="submit"> <input type="submit" name="submit" value="Upload CV" /> </p> </fieldset> </form> Link to comment https://forums.phpfreaks.com/topic/95593-edit-file-upload-help/#findComment-489374 Share on other sites More sharing options...
PRodgers4284 Posted March 11, 2008 Author Share Posted March 11, 2008 Can anyone help with this, i cant seem to find the problem? Link to comment https://forums.phpfreaks.com/topic/95593-edit-file-upload-help/#findComment-489661 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.