Image upload script not working

Discussion in 'PHP' started by vivek_master146, Nov 8, 2012.

  1. #1
    I have made a student management system which is working perfectly fine on my local machine(using WAMP Server) but when i host it, it doesn't work properly. I am trying to store student details in a database. Every detail except image path is being stored. Using wamp server its working, but it does not work when i host it.

    I also tried using whole path including domain name, folder but it doesn't help.

    Following is a code snippet:-


    
    
    if ($_POST['submit']) 
    	{
    		
    		include 'db_connect.php';	
    		$file=$_FILES['image']['tmp_name'];
    	$image= addslashes(file_get_contents($_FILES['image']['tmp_name']));
    	$image_name= addslashes($_FILES['image']['name']);
    			
    			move_uploaded_file($_FILES["image"]["tmp_name"],"photos/" . $_FILES["image"]["name"]);
    			
    			$location="photos/" . $_FILES["image"]["name"];
    					
    			
    
    		$matric = $_POST['matric'];
    $name   = $_POST['name'];
    $sem=$_POST['sem'];
    $sex=$_POST['sex'];
    $tel=$_POST['tel'];
    $address=$_POST['address'];
    $data = $_POST['picture'];
    $course = $_POST['course'];	
    		
    		$data = addslashes(fread(fopen($picture, "r"), filesize($picture)));
    
    		$pjpeg="image/pjpeg";
    		$jpeg="image/jpeg";
    		$gif="image/gif";
    		$png="image/png";
    		$bmp="image/bmp";
    
    		if ($picture_type == $pjpeg OR $picture_type == $jpg OR $picture_type == $gif OR $picture_type == $png OR $picture_type == $bmp)
    		{
    		
    		$sql="INSERT INTO info (matric, name, course, sem, sex, tel, address ,location)
    			VALUES ('$matric', '$name', '$course', '$sem', '$sex', '$tel', '$address', '$location')";
    		$result=mysql_query($sql);
    
    PHP:
     
    vivek_master146, Nov 8, 2012 IP
  2. vivek_master146

    vivek_master146 Peon

    Messages:
    134
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    One more thing, i just saw my free hosting php config. There is a line:-

    File Uploads file_uploads Whether to allow HTTP file uploads. Off

    Is it because of this only ?
     
    vivek_master146, Nov 8, 2012 IP
  3. stephan2307

    stephan2307 Well-Known Member

    Messages:
    1,277
    Likes Received:
    33
    Best Answers:
    7
    Trophy Points:
    150
    #3
    learn how to debug.

    place this code after the first {

    
    print_r($_FILES);exit;
    
    PHP:
    then review the output and look up what the output means. especially the error bit
     
    stephan2307, Nov 8, 2012 IP
  4. vivek_master146

    vivek_master146 Peon

    Messages:
    134
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Output is Array(). What does that mean ?
     
    vivek_master146, Nov 8, 2012 IP
  5. stephan2307

    stephan2307 Well-Known Member

    Messages:
    1,277
    Likes Received:
    33
    Best Answers:
    7
    Trophy Points:
    150
    #5
    that means that that no file has actually been sent.

    make sure that your form tag has this parameter in it enctype="multipart/form-data"

    ie

    
    <form action="upload_file.php" method="post" enctype="multipart/form-data">
    
    Code (markup):
     
    stephan2307, Nov 9, 2012 IP
  6. vivek_master146

    vivek_master146 Peon

    Messages:
    134
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    This is my form code's first line:-


    
    <form method="post" action="student_form.php" enctype="multipart/form-data" name='s' onsubmit='return validated()';>
    
    HTML:
     
    vivek_master146, Nov 9, 2012 IP
  7. vivek_master146

    vivek_master146 Peon

    Messages:
    134
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    @stephan

    file_uploads has been set to off in php config. Its a free hosting. I cannot change it. Is that the reason why its not working ?
     
    vivek_master146, Nov 9, 2012 IP
  8. stephan2307

    stephan2307 Well-Known Member

    Messages:
    1,277
    Likes Received:
    33
    Best Answers:
    7
    Trophy Points:
    150
    #8
    yeah that's probably why.
     
    stephan2307, Nov 9, 2012 IP
  9. vivek_master146

    vivek_master146 Peon

    Messages:
    134
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    @Stephan

    I have signed up in another website providing free hosting. I have uploaded the script. But in the new free hosting service, even the "insert into" statement is not working. Does all the free hosting services have limited php support. ?

    Any other free hosting service which provides full php support ?

    Thanks for help :)
     
    vivek_master146, Nov 9, 2012 IP
  10. stephan2307

    stephan2307 Well-Known Member

    Messages:
    1,277
    Likes Received:
    33
    Best Answers:
    7
    Trophy Points:
    150
    #10
    yeah pretty much all of the free hosts have limitations.

    what are you trying to do? maybe it is better to try it on your own computer ( install xampp or similar )
     
    stephan2307, Nov 9, 2012 IP
  11. vivek_master146

    vivek_master146 Peon

    Messages:
    134
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #11
    Yes, i have WAMP installed on my machine. Its awesome. But this is my college project, i am supposed to host it somewhere and submit the link. Web hosting is a must requirement and i dont want to remove "file upload" feature.
     
    vivek_master146, Nov 9, 2012 IP
  12. stephan2307

    stephan2307 Well-Known Member

    Messages:
    1,277
    Likes Received:
    33
    Best Answers:
    7
    Trophy Points:
    150
    #12
    try these guys www[DOT]000webhost[DOT]com.

    I don't trust them though so don't upload any sensitive data.
     
    stephan2307, Nov 9, 2012 IP