Click here to Skip to main content
15,885,890 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi,

I am getting a problem on uploading a file to database and in the website folder,
it is working fine on local even connecting with remote data base but when it checked on remote website but it show error (move_uploaded_file) not going within it.

Here is the code pls check and if you find any solution then pls send me the solution.

It always going to else part of move_uploaded_file.

Thanks in Advance


PHP
<?php
//include('mysqldbconfig.php');
session_start();
$job_title='';
$first_name='';
$last_name='';
$email='';
$current_company='';
$mobile='';
 if(isset($_POST["Submit"]))
 {
$job_title=$_POST['job_title'];
$first_name=$_POST['first_name'];
$last_name=$_POST['last_name'];
$email=$_POST['email'];
$current_company=$_POST['current_company'];
$mobile=$_POST['mobile'];
 if($_SESSION['security_code'] == $_POST['security_code'] && !empty($_SESSION['security_code']) )
{
$date=date("Y-m-d"." "."h:i:s");
$date1=date("Ymdhis");

 //This is the directory where images will be saved
 $docc=($_FILES['doc']['name']);
 $doc =$date1.str_replace(' ','',$docc);
 $target = "http://www.mywebsite.in/resumes/";
 $target = $target.basename($doc);

 // Connects to your Database
$conn mysql_connect($db_host,$username, $password) or die(mysql_error()) ;
 mysql_select_db($database) or die(mysql_error()) ; 

 //Writes the photo to the server
 if(move_uploaded_file($_FILES['doc']['tmp_name'],$target))
 {
 //Tells you if its all ok
 echo "<script>"."alert('Your Resume has been uploaded Successfully')"."</script>";

 /*"The file ". basename( $_FILES['doc']['name']). " has been uploaded, and your information has been added to the directory".$date."<br/>"; */


//Writes the information to the database
$sql="INSERT INTO career(job_title,first_name,last_name,email,current_company_name,contact_number,resumes,date) VALUES('$job_title','$first_name','$last_name','$email','$current_company','$mobile','$doc','$date');";
  mysql_query($sql,$conn) or die("Error in Query: " . mysql_error());

 $job_title='';
$first_name='';
$last_name='';
$email='';
$current_company='';
$mobile='';

 }
 else {
  //Gives and error if its not
  //echo "Sorry, there was a problem uploading your file.";
 
  echo "<script>"."alert('Sorry, There was a problem uploading your file.')"."</script>";

  }
 }
 else{
// echo "Sorry no data upload";
   echo "<script>"."alert('Sorry no data upload.')"."</script>";
 }
 }


 ?>
Posted

Your problem is in
PHP
$target = "http://www.mywebsite.in/resumes/";
$target = $target.basename($doc);


When you use $target later in move_uploaded_file, it is a filesystem path, not a URL.

The quoted block should be something like

PHP
$target = $_SERVER['DOCUMENT_ROOT'] . '/resumes/';
$target = $target . basename($doc);



Peter
 
Share this answer
 
Comments
[no name] 31-Jul-12 1:32am    
Thanks but i donot know its working now. with the same code i just change a old one.
thanks a lot
hi,
its not working first but now with this code its working.

old code
$target = "http://www.mywebsite.in/resumes/";

change

$target ="/resumes/";

thanks
 
Share this answer
 
v2
Comments
Peter_in_2780 31-Jul-12 1:39am    
That's what I suggested. Most (but not all) absolute paths in PHP are reference to the document root. I like to write it explicitly so humans can understand.
Please accept my solution so others can see.
[no name] 31-Jul-12 2:10am    
i did, peter_in_2780.
thanks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900