Wildfires Posted June 24, 2008 Share Posted June 24, 2008 Im trying to make an uploader that uploads pdf files to the server but selects the folder based on a username selected from a drop box, but i don't really know what im doing and could really do with your guys help. I have this so far: Uploader.php <?php $folder = $_POST['folder']; if ($folder == '$username') { $target_path = "invoices/$username/"; } ?> <?php // Add the original filename to image target_path $target_path = $target_path . basename( $_FILES['uploadfile']['name']); $_FILES['uploadfile']['tmp_name']; // check if the file is an image file if ($_FILES['uploadfile']['type'] == "pdf" || $_FILES['uploadfile']['type'] == "xps"){ // the file is an image if (file_exists($target_path)) { echo "The file already exists<br>"; echo "<META HTTP-EQUIV=\"Refresh\" CONTENT=\"2; URL=?x=admin\">"; exit();} // move uploaded image from tempory location into folder, display message if successfull if(move_uploaded_file($_FILES['uploadfile']['tmp_name'], $target_path)) { echo "The upload of: ". basename( $_FILES['uploadfile']['name']). " Was sucessfull<br><br>"; echo "File Name: ".$_FILES['uploadfile']['name']."<br>"; echo "File Size: ".$_FILES['uploadfile']['size']." bytes<br>"; echo "File Type: ".$_FILES['uploadfile']['type']."<br>"; echo "File location: assets/$folder/".$_FILES['uploadfile']['name']."<br>"; if ($folder !== 'categories'){ echo "<META HTTP-EQUIV=\"Refresh\" CONTENT=\"4; URL=?x=upload_image_$folder\">"; }else { echo "<META HTTP-EQUIV=\"Refresh\" CONTENT=\"4; URL=?x=category_management\">"; } } else{ echo "there was an error uploading!"; if ($folder !== 'categories'){ echo "<META HTTP-EQUIV=\"Refresh\" CONTENT=\"2; URL=?x=upload_image_$folder\">"; }else { echo "<META HTTP-EQUIV=\"Refresh\" CONTENT=\"2; URL=?x=category_management\">"; } }; } else {echo "This filetype is not allowed!"; if ($folder !== 'categories'){ echo "<META HTTP-EQUIV=\"Refresh\" CONTENT=\"2; URL=?x=upload_image_$folder\">"; }else { echo "<META HTTP-EQUIV=\"Refresh\" CONTENT=\"2; URL=?x=category_management\">"; } }; ?> upload.php $sql = "SELECT username, FROM users"; $query = mysql_query($sql); while($row = mysql_fetch_assoc($query)){ $username = ['username']; } ?> <p><form enctype="multipart/form-data" action="?x=uploader" method="post"> <select name="newsletter2" class="textinput"> <option value="1" selected><?php echo ['username'] ?> </option> </select> </p> <input name="uploadfile" type="file" class="textinput"/> <input name="folder" type="hidden" value="" class="textinput"/> <input name="submit" type="submit" value="Upload" class="input"/> </form> <br /> <br /> <a href=''>Back</a> To Admin Panel Any help would be greatly appreciated, thanks in advance. Link to comment https://forums.phpfreaks.com/topic/111592-php-drop-box-and-uploader/ Share on other sites More sharing options...
zenag Posted June 24, 2008 Share Posted June 24, 2008 <? $con=mysql_connect("localhost","root",""); mysql_select_db("database name",$con); $sql = "SELECT username FROM users"; $query = mysql_query($sql); ?> <p><form enctype="multipart/form-data" action="" method="post"> <select name="newsletter2" class="textinput"><? while($row = mysql_fetch_array($query)){ $username = $row["username"]; ?> <option value="1" selected><?php echo $username ?> </option><? }?> </select> </p> <input name="uploadfile" type="file" class="textinput"/> <input name="folder" type="hidden" value="" class="textinput"/> <input name="submit" type="submit" value="Upload" class="input"/> </form> <br /> <br /> <a href=''>Back</a> To Admin Panel Link to comment https://forums.phpfreaks.com/topic/111592-php-drop-box-and-uploader/#findComment-572928 Share on other sites More sharing options...
Wildfires Posted June 26, 2008 Author Share Posted June 26, 2008 I will give this a go asap. Thank you very much for the help. Will let you know if it works. Link to comment https://forums.phpfreaks.com/topic/111592-php-drop-box-and-uploader/#findComment-574916 Share on other sites More sharing options...
Wildfires Posted June 26, 2008 Author Share Posted June 26, 2008 I tested it, but i can't actually see where the file is being uploaded to? And there isnt any message to say that is has been uploaded. I want the uploader to upload files to a directory called http://.../invoices/*username* Thanks again. Link to comment https://forums.phpfreaks.com/topic/111592-php-drop-box-and-uploader/#findComment-574922 Share on other sites More sharing options...
zenag Posted June 26, 2008 Share Posted June 26, 2008 $con=mysql_connect("localhost","root",""); mysql_select_db("database name",$con); $upload="D:/xampp/htdocs/practice/uploa/"; $sql = "SELECT username FROM users"; $query = mysql_query($sql); if($_POST["submit"]=='Upload') { $upload_dir = "path to upload folder"; $filename = $upload_dir.$_FILES['uploadfile']['name']; if(move_uploaded_file($_FILES['uploadfile']['tmp_name'], $upload_dir.$_FILES['uploadfile']['name'])) { echo "Stored in: " . $upload_dir .$_FILES["uploadfile"]["name"]; } } Link to comment https://forums.phpfreaks.com/topic/111592-php-drop-box-and-uploader/#findComment-574954 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.