473,398 Members | 2,188 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

File can not be moved in Upload folder

Ajay Bhalala
119 64KB
Hello,

I have create a registration form in the Following path

Path : C:\Program Files (x86)\EasyPHP 2.0b1\www\Connectivity

In the folder "Connectivity", my php file "Registration.php" is created. And there is One another folder "Upload" in this folder.

Here I have create 3 file
Connectivity.php - For establish connection to database
Insert.php - For Insert Qurey
Registration.php



Here is my code of Registration.php

Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3.  
  4. <script type="text/javascript" language="javascript">
  5. function validate(frm)
  6. {
  7.     with(frm)
  8.     {
  9.         if(username.value=="")
  10.         {
  11.             alert("Please Enter Username!");
  12.             username.focus();
  13.             return false;
  14.         }
  15.         if(password.value=="")
  16.         {
  17.             alert("Please Enter Password!");
  18.             password.focus();
  19.             return false;
  20.         }
  21.         if(address.value=="")
  22.         {
  23.             alert("Please Enter Address!");
  24.             address.focus();
  25.             return false;
  26.         }
  27.         if(course.value=="" || course.value=="0")
  28.         {
  29.             alert("Please Select Course!");
  30.             course.focus();
  31.             return false;
  32.         }
  33.         if(hobby.value=="" || hobby.value=="0")
  34.         {
  35.             alert("Please Select Hobby!");
  36.             hobby.focus();
  37.             return false;
  38.         }
  39.         if(photo.value=="")
  40.         {
  41.             alert("Please Select Profile Picture!");
  42.             photo.focus();
  43.             return false;
  44.         }
  45.         if(gender.value=="")
  46.         {
  47.             alert("Please Select Gender!");
  48.             gender.focus();
  49.             return false;
  50.         }
  51.         if(!php.checked && !rdbms.checked && !java.checked && !asp.checked && !dcn.checked)
  52.         {
  53.             alert("Please Select Skill!");
  54.             php.focus();
  55.             return false;
  56.         }
  57.         return true;
  58.     }
  59. }
  60. </script>
  61. </head>
  62.  
  63.  
  64. <body>
  65. <form method="post" enctype="multipart/form-data" name="frmRegistration">
  66. <table>
  67.  
  68. <tr>
  69. <td>Enter the Username :-</td>
  70. <td>
  71. <input type="textbox" id="txtUN" name="username">
  72. </td>
  73. <tr>
  74.  
  75. <tr>
  76. <td>Enter the Password :-</td>
  77. <td>
  78. <input type="password" id="txtPassword" name="password">
  79. </td>
  80. </tr>
  81.  
  82. <tr>
  83. <td>Enter the Address :-</td>
  84. <td>
  85. <textarea id="txtPassword" name="address" rows="5" columns="10"></textarea>
  86. </td>
  87. </tr>
  88.  
  89. <tr>
  90. <td>Course :-</td>
  91. <td>
  92. <select name="course" id="course">
  93. <option value="0">Select Course</option>
  94. <option value="B.Sc.IT">B.Sc.IT</option>
  95. <option value="BCA">BCA</option>
  96. <option value="B.Com">B.Com</option>
  97. <option value="BBA">BBA</option>
  98. <option value="M.Sc.IT">M.Sc.IT</option>
  99. <option value="MCA">MCA</option>
  100. <option value="M.Com">M.Com</option>
  101. <option value="MBA">MBA</option>
  102. </select>
  103. </td>
  104. </tr>
  105.  
  106. <tr>
  107. <td>Hobby :-</td>
  108. <td>
  109. <select name="hobby" id="hobby" multiple="multiple">
  110. <option value="0" selected>Please Select</option>
  111. <option value="Reading">Reading</option>
  112. <option value="Writing">Writing</option>
  113. <option value="Collecting Different Things">Collecting Different Things</option>
  114. <option value="Travelling">Travelling</option>
  115. <option value="Walking">Walking</option>
  116. <option value="Playing">Playing</option>
  117. <option value="Cooking">Cooking</option>
  118. <option value="Music">Music</option>
  119. <option value="Other">Other</option>
  120. </select>
  121. </td>
  122. </tr>
  123.  
  124. <tr>
  125. <td>Profile Picture :-</td>
  126. <td>
  127. <input type="file" name="photo"/>
  128. </td>
  129. </tr>
  130.  
  131. <tr>
  132. <td>Gender :-</td>
  133. <td>
  134. <input type="radio" name="gender" value="Male">Male
  135. <input type="radio" name="gender" value="Female">Female
  136. </td>
  137. </tr>
  138.  
  139. <tr>
  140. <td>Skills :-</td>
  141. <td>
  142. <input type="checkbox" name="php" value="PHP">PHP
  143. <input type="checkbox" name="rdbms" value="RDBMS">RDBMS
  144. <input type="checkbox" name="java" value="Java">Java
  145. <input type="checkbox" name="asp" value="ASP.NET">ASP.NET
  146. <input type="checkbox" name="dcn" value="DCN">DCN
  147. </td>
  148. </tr>
  149.  
  150. <tr>
  151. <td colspan="2">
  152. <br>
  153. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  154. <input type="submit" name="submit" value="Submit" onclick="javascript:return validate(document.frmRegistration);">
  155. <input type="reset" name="clear" value="Reset">
  156. <br><br>
  157. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  158. <input type="submit" name="view" value="  View Records  ">
  159. </td>
  160. </tr>
  161.  
  162. </table>
  163. </form>
  164. <?php
  165. if(isset($_POST["submit"]))
  166. {
  167.  
  168.     if($_FILES["photo"]["name"]!=" ")
  169.     {
  170.     /*echo "<pre>";
  171.     print_r($_FILES);
  172.     echo "</pre>";*/
  173.     $target="Upload/";
  174. echo $target.$_FILES["photo"]["name"];die;
  175.         if(!file_exists($target.$_FILES["photo"]["name"]))
  176.         {
  177.             move_uploaded_file($_FILES["photo"]["tmp_name"],$target.$_FILES["photo"]["name"]);
  178.             $photo=$_FILES["photo"]["name"];
  179.         }
  180.         else
  181.         {
  182.             echo "Already exists!<br>";
  183.         }
  184.     }
  185. include("Insert.php");
  186. }
  187. ?>
  188. </body>
  189. </html>
  190.  
When I have submit the form, the data are inserted successfully, but the photo doesn't move in "Upload" folder.

Here, Line 168 to 184 is code for File Upload.

What changes I have to do in my code for save the image/photo in "Upload" folder?????

Please help me to solve this problem



If need to view other 2 files, here is the code

Code of Insert.php
Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3. include("Connectivity.php");
  4.  
  5. if(isset($_POST["submit"]))
  6. {
  7. extract($_POST);
  8.  
  9. $php=isset($_POST["php"])?$_POST["php"]:"";
  10. $rdbms=isset($_POST["rdbms"])?$_POST["rdbms"]:"";
  11. $java=isset($_POST["java"])?$_POST["java"]:"";
  12. $asp=isset($_POST["asp"])?$_POST["asp"]:"";
  13. $dcn=isset($_POST["dcn"])?$_POST["dcn"]:"";
  14.  
  15. $Password=md5($password);
  16.  
  17. $sql="insert into registration(
  18.         Username,Password,Address,
  19.         Course,Hobby,ProfilePic,Gender,
  20.         PHP,RDBMS,JAVA,ASP,DCN
  21.         ) 
  22.         values(
  23.         ' ".$username." ',' ".$Password." ',' ".$address." ',' ".
  24.         $course." ',' ".$hobby." ',' ".$photo." ',' ".$gender." ',' ".
  25.         $php." ',' " .$rdbms." ',' ".$java." ',' ".$asp." ',' ".$dcn." ')";
  26. //echo $sql;die;
  27. mysql_query($sql);
  28. echo "Successfully Inserted";
  29. }
  30. ?>
  31.  


Code of Connectivity.php
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $host="localhost";
  3. $username="root";
  4. $password="";
  5. $link=mysql_connect($host,$username,$password);
  6.  
  7. if($link)
  8. {
  9. mysql_select_db("student",$link);
  10. }
  11. else
  12. {
  13. echo "Error!";
  14. die;
  15. }
  16. ?>
  17.  
Jan 4 '16 #1
3 1261
Dormilich
8,658 Expert Mod 8TB
Please help me to solve this problem
like most PHP functions, move_uploaded_file() returns FALSE if there is a problem.

From the Manual:
If filename is a valid upload file, but cannot be moved for some reason, no action will occur, and move_uploaded_file() will return FALSE. Additionally, a warning will be issued.
so, yes, enable error reporting and check what the message says.
Jan 5 '16 #2
Ajay Bhalala
119 64KB
Hello,
Thanks for your reply

error reporting is already on.

But there is no any message display.
Jan 7 '16 #3
Dormilich
8,658 Expert Mod 8TB
then check for the return value.
Jan 7 '16 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Cindy Liu | last post by:
Hi, If my xml resource file is directly under my project file, I have no problem to load that xml file via Assembly.GetManifestResourceStream. However, after I create a folder under the project...
5
by: tolgademirel | last post by:
I am creating a web application which needs to access data which resides on the client's computer. The data is a bunch of text files that are stored in a folder. I need all of those text files....
1
by: sonu | last post by:
Can we upload folder as it is from client to server in .NET Please give me link of sites or any other information regarding this
2
by: Simon | last post by:
I'm following microsoft's guide on how to upload files. I want to upload AND rename the file... Anyone have some tips for how to do that? Thanks ------ If Not File1.PostedFile Is Nothing And...
3
by: Trista | last post by:
I moved my folder to another location on the same drive and now my form's scroll bars don't work. Please help! Thank you.
9
by: Paul | last post by:
I'm trying to make get my app to delete all the files in a specified folder and all the files within the folders of the specified folder. e.g. Folder 1 contains three files (File1, File2, File3)...
2
by: =?Utf-8?B?Y2hlcXVlcg==?= | last post by:
Windows XP Pro SP2 How can I remove the Share-to-Web Upload Folder Icon from the desktop? What are the consequences of doing this? Can I put it somewhere else other than the Desktop? Is it...
3
by: Bill H | last post by:
I have written many programs for file / image upload over the years in perl, but know that I am working more in php I find I need to be able to do it in php now. I was gonna just do a google serach...
2
by: fran7 | last post by:
Hi, I wonder if anyone could tell me if there is a default upload folder for image uploads in this code or if the code references another file. It works fine but I am trying to change the upload...
1
by: kiranvn31 | last post by:
Hi I write code for save my Image file in one folder The code as follow : SavePath = Server.MapPath("~/images/masterpageimage/"); MasterFile.Save(SavePath + fname);
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.