Jump to content

Uploaded file lost?


dan_t

Recommended Posts

Hi guys,

Here's my upload file.

 $target = "./images/";  $target = $target . basename( $_FILES['uploaded']['name']) ;  $ok=1;   
//This is the sizing condition
   if ($uploaded_size > 350000)  {  echo "Your file is too large.<br>";  $ok=0;  }  
    //This is the file type limit condition
    if ($uploaded_type == "text/php")  {  echo "No PHP files<br>";  $ok=0;  }

	  if ($uploaded_type == "text/css")  {  echo "No CSS files<br>";  $ok=0;  }

		 if ($uploaded_type == "text/javascript")  {  echo "No Javascript files<br>";  $ok=0;  }
	    
	        if ($ok==0)  {  Echo "Sorry your file was not uploaded";  }
	    
		  else  {  if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target))  {  echo "The file ". basename( $_FILES['uploaded']['name']). " has been uploaded <br /> Thank you.<br />Your photo will be reviewed for submittance.<br /> This insures the integrity of the site.";  }  else  {  echo "Sorry, there was a problem uploading your file.";  }  }

 

 

now of coarse my validation doesn't seem to validate, but my real problem is when it goes into the image folder with some crazy number I loose track of who it came from.

Is there any way to name it in the database?

Here is the form if you need it.

<form enctype="multipart/form-data" action="upload.php" method="POST"> Please choose a file: 
<input name="uploaded" type="file" /><br />
  <input type="submit" value="Upload" /> </form>

Link to comment
https://forums.phpfreaks.com/topic/202789-uploaded-file-lost/
Share on other sites

dan_t,

 

    I did not get "some crazy number" on my uploaded files.  I uploaded 5.jpg from my Windows C: drive and the file ended up in my images folder as 5.jpg.

 

I altered you code to validate correctly.

 

Scot L. Diddle, Richmond VA

 


<?php

Header("Cache-control: private, no-cache");
Header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
Header("Pragma: no-cache");

$target = "./images/";
$target = $target . basename( $_FILES['uploaded']['name']) ;

$ok=1;

$uploaded_name = $_FILES['uploaded']['name']; // Added
$uploaded_size = $_FILES['uploaded']['size']; // Added
$uploaded_type = $_FILES['uploaded']['type']; // Added

    //This is the sizing condition

   if ($uploaded_size > 350000)  {

   	   echo "Your file is too large.<br>";
   	   $ok=0;

   }
    //This is the file type limit condition
    if ( ($uploaded_type == "application/octet-stream") || ($uploaded_type == "text/css"))  {

    	$fileNamePieces = explode('.', $uploaded_name); // Added

    	$ext = array_pop($fileNamePieces); // Added

    	$ext = strtolower($ext); // Added

    	switch ($ext) { // Added

    		case 'php' :

    			echo "No PHP files<br>";
    			$ok=0;

    		break;

    		case 'js' :

    			echo "No javascript files<br>";
    			$ok=0;

    		break;

    		case 'css' :

    			echo "No css files<br>";
    			$ok=0;

    		break;

    		default :

    			echo "File with ext = $ext passed edit test.<br />
    				  If this is not what you want, modify upload.php switch(\$ext) tests...<br /><br /> \n";

    		break;


    	} // END Added

    }

if ($ok==0)  {
	Echo "Sorry your file was not uploaded";
}
else  {

	if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target))  {

		$baseName = basename( $_FILES['uploaded']['name']); // Added

  		echo "The file ". $baseName. " has been uploaded <br />
  			  Thank you.<br />Your photo will be reviewed for submittance.<br />
  			  This insures the integrity of the site."; // Changed
  	}
  	else  {
  		echo "Sorry, there was a problem uploading your file.";
  	}

}

?>

Link to comment
https://forums.phpfreaks.com/topic/202789-uploaded-file-lost/#findComment-1062962
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.