SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    Patience... bronze trophy solidcodes's Avatar
    Join Date
    Jul 2006
    Location
    Philippines
    Posts
    936
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)

    Arrow It's not uploading files?

    hi, i hope there is kind people that can help me here.
    The only problem is, after pressing the upload button
    and then checking the directory i saw no files, what i mean is there is no file being uploaded into the specified directory, why is this?

    I know this is working before, i just can't figure it out right now, i'm lost.

    can someone please guide meh.

    preupload.php
    Code:
    <?php
    session_start();
    
    //remove white spaces and periods.
    $string = $_POST['name'];
    $replace_what = array(" ", ".");
    $replace_with = array("","");
    $cut_name = str_replace($replace_what, $replace_with, $string); 
    
    //store directory name into memory.
    $_SESSION['tempdir'] = $cut_name;
    	
    //make directory folder using $cut_name
    mkdir("$cut_name", 0777);
    ?>
    
    <?php 
    if (isset($_POST['Submit'])) {    
    $recepient = "contact@travelsconsult.com";
    $subject = "You have Guest! from travelsconsult.com/model/";    
    $contents = "Full Name:  " . $_POST['name'] .    			
    "\n\nAddress:  " . $_POST['address'] .    			
    "\n\nAge:  " . $_POST['age'] .    			
    "\n\nStatus:  " . $_POST['status'] .    			
    "\n\nEtnicity:  " . $_POST['ethnicity'] .    			
    "\n\nHeight:  " . $_POST['height'] .    			
    "\n\nChest:  " . $_POST['chest'] .				
    "\n\nWaist:  " . $_POST['waist'] .    			
    "\n\nHips:  " . $_POST['hips'] .    			
    "\n\nWeight:  " . $_POST['weight'] .    			
    "\n\nHair:  " . $_POST['hair'] .    			
    "\n\nEyes:  " . $_POST['eyes'] .    			
    "\n\nContact:  " . $_POST['contact'] .    			
    "\n\nEmail:  " . $_POST['email'] .    			
    "\n\nCountry:  " . $_POST['country'] .    			
    "\n\nPrevious job:  " . $_POST['previousjob'] .    			
    "\n\nPresent job:  " . $_POST['presentjob'] .    			
    "\n\nEducation:  " . $_POST['education'];}    
    
    $headers = "Reply-to: contact@travelsconsult.com\n";    
    mail($recepient, $subject, $contents, "From: contact@travelsconsult.com");
    ?>
    
    
    <?php
    	// initialization
    	$photo_upload_fields = "";
    	$counter = 1;
    
    	// default number of fields
    	$number_of_fields = 5;
    
    echo "<br><br><center><h3>";
    echo "Please Upload your latest photo full and half body.";
    echo "</h3></center>";
    
    // Lets build the Photo Uploading fields
    	while($counter <= $number_of_fields)
    	{
    $photo_upload_fields .=<<<__HTML_END
    <tr>
    	<td>
    	     Photo {$counter}:
    	    <input name='photo_filename[]' type='file' />
    	</td>
    </tr>
    __HTML_END;
    	$counter++;
    	}
    
    // Final Output
    echo <<<__HTML_END
    <html>
    <head>
    	<title>Lets upload Photos</title>
    </head>
    <body>
    <form enctype='multipart/form-data' action='upload.php' method='post' name='upload_form'>
    <input type="hidden" name="MAX_FILE_SIZE" value="10000" />
    
    <table width='90%' border='0' align='center' style='width: 90%;'>
    
    <!-Insert the photo fields here -->
    $photo_upload_fields
    
    <tr>
    	<td>
    	        <input type='submit' name='submit' value='Add Photos' />
    	</td>
    </tr>
    </table>
    </form>
    </body>
    </html>
    __HTML_END;
    ?>
    here is the upload.php
    Code:
    <?php
    session_start();
    	// initialization
    	$result_final = "";
    	$counter = 0;
    	$cut_name = $_SESSION['tempdir'];
    	#$images_dir = $_SERVER['DOCUMENT_ROOT'].'/mygallery/photos/';
    	$images_dir = 'http://' . $_SERVER['HTTP_HOST'] . '/model/$cut_name';
    	
    	// List of our known photo types
    	$known_photo_types = array(
    						'image/pjpeg' => 'jpg',
    						'image/jpeg' => 'jpg',
    						'image/gif' => 'gif',
    						'image/bmp' => 'bmp',
    						'image/x-png' => 'png'
    					);
    
    	// GD Function List
    	$gd_function_suffix = array(
    						'image/pjpeg' => 'JPEG',
    						'image/jpeg' => 'JPEG',
    						'image/gif' => 'GIF',
    						'image/bmp' => 'WBMP',
    						'image/x-png' => 'PNG'
    					);
    
    	// Fetch the photo array sent by preupload.php
    	$photos_uploaded = $_FILES['photo_filename'];
    
    	while($counter < count($photos_uploaded)) {
    		if($photos_uploaded['size'][$counter] > 0)
    		{
    				$filename = $photos_uploaded['name'][$counter];
    				$tmpname = $photos_uploaded['tmp_name'][$counter];
    				$filesize = $photos_uploaded['size'][$counter];
    				$filetype = $photos_uploaded['type'][$counter];
    
    			//check the file if it is an image
    			if(!array_key_exists($photos_uploaded['type'][$counter], $known_photo_types))
    			{
    				$result_final .= "<b>".($filename)."</b>";
    				$result_final .= " is not a photo <br />";
    			}
    			else
    			{
    
    		chdir($_SERVER['DOCUMENT_ROOT'].'/');
    		chdir('/model/$cut_name');
    		
    		//append file if it is not exist in /photos/ directory.
    		if(!file_exists($filename)) {
    			//checks if the file is
    			if(is_uploaded_file($filename));
    			{
    				echo "<strong>";
    				echo $filename, "<br>";
    				echo "</strong>";
    			}
    		}
    
    	//check for duplicate, if no duplicate then insert and upload.
    	//if $filename equal to filename in the photo table then don't insert and upload.
    	//check the existence of $filename if exist then echo message.
    		if(file_exists($filename)) {
    			echo "<b>".($filename)."</b>", "  already exist! Please rename $filename ";
    			echo "<br>";
    		} else
    		{
    			//upload the file
    			$uploaddir = $_SERVER['DOCUMENT_ROOT'].'/model/$cut_name';
    			$uploadfile = $uploaddir . $filename;
    			$dir_handler = $images_dir . $filename;
    
    			if (move_uploaded_file($tmpname, $uploadfile)) {
    				echo "Upload successful! <br>";
    				echo "<img src=$dir_handler />";
    				echo "<br>";
    			} else {
    				print "Failed to upload! <br>";
    			}
    
    				}
    			}
    	echo $result_final;
    		}
    	$counter++;
    	}
    ?>

    Thank you very much in advance.

  2. #2
    Non-Member
    Join Date
    Aug 2006
    Posts
    51
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What is the size of the file you are planning to upload?.Is it is greater than upload maximum size in php.ini?

  3. #3
    SitePoint Enthusiast
    Join Date
    Feb 2007
    Location
    Swindon, UK
    Posts
    50
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    And you are not getting any of the error messages come up?
    First thing I would do is check the value of your variables - check $cut_name etc are what you expect. Failing that, check the permissions of the directory.

  4. #4
    SitePoint Zealot
    Join Date
    Mar 2007
    Posts
    192
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    use print_r($_FILES) to make sure the files are being uploaded. also check your upload_max_size and post_max_size variable in php.ini


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •