PHP School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become a PHP Expert!

Join 307,145 PHP Programmers for FREE! Get instant access to thousands of PHP experts, tutorials, code snippets, and more! There are 1,729 people online right now. Registration is fast and FREE... Join Now!




condition in uploading

 

condition in uploading

rkmalbz

5 Nov, 2009 - 03:03 PM
Post #1

New D.I.C Head
*

Joined: 10 Aug, 2009
Posts: 26


My Contributions
CODE


                if ($_POST["action"] == "Upload") {

                  $folder = "storages/";
                  move_uploaded_file($_FILES["filep"]["tmp_name"] , "$folder".$_FILES["filep"]["name"]);
                  echo "<br/>
                  <p align=center>Filename \"<b>".$_FILES["filep"]["name"]. "</b>\" Loaded";

                  $resultz = mysql_query("INSERT into storages VALUES($_POST[fileid],'".$_FILES['filep']['name']."','$_POST[entrydesc]')");
                  if($resultz) {
                        echo "<script>self.location='adminpage.php'</script>";
                    }
                }

echo "<tr>
                        <td><input type='hidden' name='fileid' value=". $curid ." /></td>
                      </tr>
                      <tr>
                        <input type='hidden' name='MAX_FILE_SIZE' value='10000000' />
                        <td style='padding: 3px 10px 0px 50px;font:12px tahoma'>Filename</td>
                        <td><input type='file' name='filep' /></td>
                      </tr>
                      <tr valign='top'>
                        <td style='padding: 3px 10px 0px 50px;font:12px tahoma'>File Description</td>
                        <td><textarea style='width:350px;height:150px' name='entrydesc'></textarea></td>
                      </tr>
                      <tr>
                        <td><input type='hidden' name='dates' value=" . $dates ." /></td>
                        <td colspan='2' align='right'><input type='submit' name='action' value='Upload' /></td>
                      </tr>";



hi this is my code in uploading my files to a folder in root directory and the filename to the mysql database. it works but my question is..how do i set restriction like if the file already exist there should error message that says the filename is already exist or something..how do i do that and where can i place it??

This post has been edited by rkmalbz: 5 Nov, 2009 - 03:05 PM

User is offlineProfile CardPM
+Quote Post


RudiVisser

RE: Condition In Uploading

5 Nov, 2009 - 03:57 PM
Post #2

.. does not guess solutions
Group Icon

Joined: 5 Jun, 2009
Posts: 1,891



Thanked: 139 times
Dream Kudos: 125
Expert In: PHP, MySQL, HTML, CSS, C#

My Contributions
You can make a simple call to file_exists to check if a file exists, you'd obviously place it before the call to move_uploaded_file.

Could you define "or something"?
User is offlineProfile CardPM
+Quote Post

rkmalbz

RE: Condition In Uploading

6 Nov, 2009 - 02:54 PM
Post #3

New D.I.C Head
*

Joined: 10 Aug, 2009
Posts: 26


My Contributions
thank you sir for the reply..im going to research about this..
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/21/09 03:44PM

Live PHP Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

PHP Tutorials

Reference Sheets

PHP Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month