Jump to content

Recommended Posts

This is my code:

<?php
require_once 'header.php';
if(!isset($_SESSION['advert']))
{
header("Location:http://".$_SERVER['HTTP_HOST']."/advertise.php");
}
if(isset($_GET['logout']))
{
session_unset();
session_destroy();
header("Location:http://".$_SERVER['HTTP_HOST']."/advertise.php");
}
$email = $_SESSION['email'];

if(isset($_POST['upload']))
{
$target = "img/logos/";
$name = mysql_real_escape_string($_FILES['uploaded']['name']);
$image = $target.$name;
//if(file_exists($image))
//{
	//$image = $target.$name.rand(1,100);
//}
$target = $target . basename( $_FILES['uploaded']['name']) ; 
//$size = $_FILES['uploaded']['size'];
//$extension = substr($name, strrpos($name, "."), strlen($name));
$location = "http://".$_SERVER['HTTP_HOST']."/".$target;
echo "Upload: " . $_FILES["uploaded"]["name"] . "<br />";
echo "Type: " . $_FILES["uploaded"]["type"] . "<br />";
echo "Size: " . ($_FILES["uploaded"]["size"] / 1024) . " Kb<br />";
echo "Stored in: " . $_FILES["uploaded"]["tmp_name"]."<br>";	
echo "Error: ".$_FILES['uploaded'] ['error'];

if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target))
{
	echo "<br>The file " . $_FILES['uploaded']['name']." has been uploaded.<br />";
	echo "Upload: " . $_FILES["uploaded"]["name"] . "<br />";
	echo "Type: " . $_FILES["uploaded"]["type"] . "<br />";
	echo "Size: " . ($_FILES["uploaded"]["size"] / 1024) . " Kb<br />";
	echo "Stored in: " . $_FILES["uploaded"]["tmp_name"]."<br>";
	mysql_query("UPDATE Companies SET logo_url = '$location' WHERE email = '$email'");
echo "Error: ".$_FILES['uploaded'] ['error'];	
}
else
{
	echo "Sorry, there was a problem uploading your file.";
} 
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>All About Weddings</title>
<meta name="author" content="">
<link rel="stylesheet" href="weddings.css" type="text/css">
</head>

<body>
<form enctype="multipart/form-data" action="<?php $_SERVER['PHP_SELF'] ?>" method="post">
<input type="hidden" name="MAX_FILE_SIZE" value="30000" />
Please choose a file: <input name="uploaded" type="file"/><br />
<input type="submit" value="Submit" name="upload" />
</form>
<?php
echo ini_get('post_max_size')."<br>".ini_get('upload_max_filesize');
mysql_close();
?>
</body></html>

 

for some reason its not allowing most images to even get stored in the temp files.

So far the largest image that has reached the temp file, is just under 5kb.

 

The ini post_max_size is 8mb, and the upload_max_filesize is 2mb.

 

Most of the code is just trying to debug this problem, but from the above code it shows that the file is isnt being stored temporarily while i perfrom checks(unless its really small), any one know why?

Btw , i have tried changing the hidden max size, and that doesnt do anything.

 

 

Scrap that, it now seems to be working. :D

 

Link to comment
https://forums.phpfreaks.com/topic/125866-upload-form-not-allowing-certain-images/
Share on other sites

New problem , file_exist doesnt seem to be working,  yet im on PHP 5.2.6. Is it only avaible in later ones.

 

I have this code now, how can i change the file name if the file exists, my way produces errors (i think becuase of the file name change , but not the temp name)

<?php
function file_present($var)
{
if (@fclose(@fopen($var, "r"))) 
{
	return true;
}
else
{
	return false;
}
}
require_once 'header.php';
if(!isset($_SESSION['advert']))
{
header("Location:http://".$_SERVER['HTTP_HOST']."/advertise.php");
}
if(isset($_GET['logout']))
{
session_unset();
session_destroy();
header("Location:http://".$_SERVER['HTTP_HOST']."/advertise.php");
}
$email = $_SESSION['email'];

if(isset($_POST['upload']))
{
$target = "img/logos/";
$name = mysql_real_escape_string($_FILES['uploaded']['name']);
$image = $target.$name;
$location = "http://".$_SERVER['HTTP_HOST']."/".$image;
if (file_present($location) == true) 
{
	$image = $target.$name.rand(1,100);
}
$target = $target . basename( $_FILES['uploaded']['name']) ; 
$size = $_FILES['uploaded']['size'];
$extension = $_FILES["uploaded"]["type"];
$location = "http://".$_SERVER['HTTP_HOST']."/".$target;
if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target))
{
	echo "<br>The file " . $_FILES['uploaded']['name']." has been uploaded.<br />";
	echo "Upload: " . $_FILES["uploaded"]["name"] . "<br />";
	echo "Type: " . $_FILES["uploaded"]["type"] . "<br />";
	echo "Size: " . ($_FILES["uploaded"]["size"] / 1024) . " Kb<br />";
	echo "Stored in: " . $_FILES["uploaded"]["tmp_name"]."<br>";
	mysql_query("UPDATE Companies SET logo_url = '$location' WHERE email = '$email'");
}
else
{
	echo "Sorry, there was a problem uploading your file.";
} 
}
?>

 

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.