Page 1 of 1

uploading pictures

Posted: Tue Jun 22, 2004 9:31 pm
by azqnow
need help in uploading files heres the code.. the problem is file size.. im a newbie i dont know how to upload files with varying sizes and file types.. i want to upload different kind of files but this one is for pictures only specifically jpeg

//========= uploadpic.php ==============

Code: Select all

<?php
$city = $_POST['city'];
$i = $_POST['i'];
$city = trim($city);
$userfile = $_FILES['userfile']['tmp_name'];
$userfile_name = $_FILES['userfile']['name'];
$userfile_size = $_FILES['userfile']['size'];
$userfile_type = $_FILES['userfile']['type'];
if ($userfile == "none") {
	echo "<html>";
	echo "<head>";
	       echo "<title>Port Information System: Picture Upload For $city</title>";
		echo "<link rel="stylesheet" type="text/css" href="display.css" />";
	echo "<META HTTP-EQUIV=Refresh CONTENT="2; URL=".getenv("HTTP_REFERER")."">";
	echo "</head>";
	echo "<body>";
	exit("<center><br><br><br><br><br><br><br><br><br><br><h3>Problem: no file uploaded</h3></center>");
}
if ($userfile_size == 0) {
	echo "<html>";
	echo "<head>";
	       echo "<title>Port Information System: Picture Upload For $city</title>";
		echo "<link rel="stylesheet" type="text/css" href="display.css" />";
	echo "<META HTTP-EQUIV=Refresh CONTENT="2; URL=".getenv("HTTP_REFERER")."">";
	echo "</head>";
	echo "<body>";
	exit("<center><br><br><br><br><br><br><br><br><br><br><h3>Problem: uploaded file is zero length</h3></center>");
}
if ($userfile_size > 800000000) {
	echo "<html>";
	echo "<head>";
	       echo "<title>Port Information System: Picture Upload For $city</title>";
		echo "<link rel="stylesheet" type="text/css" href="display.css" />";
	echo "<META HTTP-EQUIV=Refresh CONTENT="2; URL=".getenv("HTTP_REFERER")."">";
	echo "</head>";
	echo "<body>";
	exit("<center><br><br><br><br><br><br><br><br><br><br><h3>Problem: uploaded file is greater than 8mb</h3></center>");
}
if ($userfile_type == "text/plain") {
	echo "<html>";
	echo "<head>";
	       echo "<title>Port Information System: Picture Upload For $city</title>";
		echo "<link rel="stylesheet" type="text/css" href="display.css" />";
	echo "<META HTTP-EQUIV=Refresh CONTENT="2; URL=".getenv("HTTP_REFERER")."">";
	echo "</head>";
	echo "<body>";
	exit("<center><br><br><br><br><br><br><br><br><br><br><h3>Problem: file is not image</h3></center>");
}

if (!is_uploaded_file($userfile)) {
	echo "<html>";
	echo "<head>";
	       echo "<title>Port Information System: Picture Upload For $city</title>";
		echo "<link rel="stylesheet" type="text/css" href="display.css" />";
	echo "<META HTTP-EQUIV=Refresh CONTENT="2; URL=".getenv("HTTP_REFERER")."">";
	echo "</head>";
	echo "<body>";
	exit("<center><br><br><br><br><br><br><br><br><br><br><h3>Problem: possible file upload attack</h3></center>");
}
header("Location: ".getenv("HTTP_REFERER"));
$upfile = "../litrato/".$userfile_name;
$upfile2 = "../litrato/".$i.$city.".jpg";
rename($upfile, $upfile2);
if (!copy($userfile, $upfile2)){
	echo "<center><br><br><br><br><br><br><br><br><br><br><h3>Problem: Could not move file into directory</h3></center>";
	exit;
}
//echo "File uploaded successfully<br><br>";
?>
</body>
</html>
// end of uploadpic.php ===============================


feyd | use

Code: Select all

tags when posting code; Read [/color][url=http://forums.devnetwork.net/viewtopic.php?t=21171] [color=red][u][b]Posting Code in the Forums[/b][/u][/color][/url].

Posted: Tue Jun 22, 2004 9:52 pm
by Illusionist
times like these i wish i was a mod!

1)Post this type of question the Programming Section under PHP-Code
2)use tags when posting php code

Posted: Wed Jun 23, 2004 9:38 am
by pickle
Read the section of the manual regarding uploading via HTTP. There's a form element that can set the max uploaded file size.