Jump to content

Recommended Posts

Hi I wander if someone here can help

I have downloaded this script from here http://digitarald.de/playground/uploader.html

 

the developer says I need my own upload script so i have tried to use the following

which seems to come up with Invalid file all the time. the uploads directory does exist with 777 permissions

anyone any idea's?

 

<?php
if (($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/png")
|| ($_FILES["file"]["type"] == "image/pjpeg")
|| ($_FILES["file"]["type"] == "application/pdf")
&& ($_FILES["file"]["size"] < 20000))
{
if ($_FILES["file"]["error"] > 0)
{
echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
}
else
{
echo "Upload: " . $_FILES["file"]["name"] . "<br />";
echo "Type: " . $_FILES["file"]["type"] . "<br />";
echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />"; if 

(file_exists("uploads/" . $_FILES["file"]["name"]))
{
echo $_FILES["file"]["name"] . " already exists. ";
}
else
{
move_uploaded_file($_FILES["file"]["tmp_name"],
"uploads/" . $_FILES["file"]["name"]);
echo "Stored in: " . "uploads/" . $_FILES["file"]["name"];
}
}
}
else
{
echo "Invalid file";
}
?>

Link to comment
https://forums.phpfreaks.com/topic/90566-php-upload-script/
Share on other sites

Never use the "||" statement, because it will never come out true.

 

Try

 

<?php
$file_types = array("image/png","image/jpeg","image/gif"); // keeep adding to it
if ((in_array($_FILES["file"]["type"],$file_types))&& ($_FILES["file"]["size"] < 20000)){code]

?>

You can keep adding to the array

Link to comment
https://forums.phpfreaks.com/topic/90566-php-upload-script/#findComment-464341
Share on other sites

I have now tried the following still the same error

 

<?php
$file_types = array("image/png","image/jpeg","image/gif"); // keeep adding to it
if ((in_array($_FILES["file"]["type"],$file_types))&& ($_FILES["file"]["size"] > 2000))
{
if ($_FILES["file"]["error"] > 0)
{
echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
}
else
{
echo "Upload: " . $_FILES["file"]["name"] . "<br />";
echo "Type: " . $_FILES["file"]["type"] . "<br />";
echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />"; if 

(file_exists("./uploads/" . $_FILES["file"]["name"]))
{
echo $_FILES["file"]["name"] . " already exists. ";
}
else
{
move_uploaded_file($_FILES["file"]["tmp_name"],
"./uploads/" . $_FILES["file"]["name"]);
echo "Stored in: " . "./uploads/" . $_FILES["file"]["name"];
}
}
}
else
{
echo "Invalid file";
}
?>

Link to comment
https://forums.phpfreaks.com/topic/90566-php-upload-script/#findComment-464349
Share on other sites

I have now tried the following still the same error

 

<?php
$file_types = array("image/png","image/jpeg","image/gif"); // keeep adding to it
if ((in_array($_FILES["file"]["type"],$file_types))&& ($_FILES["file"]["size"] > 2000))
{
if ($_FILES["file"]["error"] > 0)
{
echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
}
else
{
echo "Upload: " . $_FILES["file"]["name"] . "<br />";
echo "Type: " . $_FILES["file"]["type"] . "<br />";
echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />"; if 

(file_exists("./uploads/" . $_FILES["file"]["name"]))
{
echo $_FILES["file"]["name"] . " already exists. ";
}
else
{
move_uploaded_file($_FILES["file"]["tmp_name"],
"./uploads/" . $_FILES["file"]["name"]);
echo "Stored in: " . "./uploads/" . $_FILES["file"]["name"];
}
}
}
else
{
echo "Invalid file";
}
?>

 

 

 

The file can be a Pjpeg or something your not expecting. Echo the File Type as Said by KishanForum.

Link to comment
https://forums.phpfreaks.com/topic/90566-php-upload-script/#findComment-464357
Share on other sites

here is where I put it, I really only know basic PHP desperate to get this upload script working

 

<?php
$file_types = array("image/png","image/jpeg","image/gif"); // keeep adding to it
echo $_FILES['file']['type'];
if ((in_array($_FILES["file"]["type"],$file_types))&& ($_FILES["file"]["size"] > 2000))
{
if ($_FILES["file"]["error"] > 0)
{
echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
}
else
{
echo "Upload: " . $_FILES["file"]["name"] . "<br />";
echo "Type: " . $_FILES["file"]["type"] . "<br />";
echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />"; if 

(file_exists("./uploads/" . $_FILES["file"]["name"]))
{
echo $_FILES["file"]["name"] . " already exists. ";
}
else
{
move_uploaded_file($_FILES["file"]["tmp_name"],
"./uploads/" . $_FILES["file"]["name"]);
echo "Stored in: " . "./uploads/" . $_FILES["file"]["name"];
}
}
}
else
{
echo "Invalid file";
}
?>

Link to comment
https://forums.phpfreaks.com/topic/90566-php-upload-script/#findComment-464375
Share on other sites

here is where I put it, I really only know basic PHP desperate to get this upload script working

 

<?php
$file_types = array("image/png","image/jpeg","image/gif"); // keeep adding to it
echo $_FILES['file']['type'];
if ((in_array($_FILES["file"]["type"],$file_types))&& ($_FILES["file"]["size"] > 2000))
{
if ($_FILES["file"]["error"] > 0)
{
echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
}
else
{
echo "Upload: " . $_FILES["file"]["name"] . "<br />";
echo "Type: " . $_FILES["file"]["type"] . "<br />";
echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />"; if 

(file_exists("./uploads/" . $_FILES["file"]["name"]))
{
echo $_FILES["file"]["name"] . " already exists. ";
}
else
{
move_uploaded_file($_FILES["file"]["tmp_name"],
"./uploads/" . $_FILES["file"]["name"]);
echo "Stored in: " . "./uploads/" . $_FILES["file"]["name"];
}
}
}
else
{
echo "Invalid file";
}
?>

I told you

 

<?php echo $_FILES['file']['type']; ?>

 

try

 

]<?php echo $_FILES['file']['type']; ?><?php
$file_types = array("image/png","image/jpeg","image/gif"); // keeep adding to it
echo $_FILES['file']['type'];
if ((in_array($_FILES["file"]["type"],$file_types))&& ($_FILES["file"]["size"] > 2000))
{
if ($_FILES["file"]["error"] > 0)
{
echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
}
else
{
echo "Upload: " . $_FILES["file"]["name"] . "<br />";
echo "Type: " . $_FILES["file"]["type"] . "<br />";
echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />"; if 

(file_exists("./uploads/" . $_FILES["file"]["name"]))
{
echo $_FILES["file"]["name"] . " already exists. ";
}
else
{
move_uploaded_file($_FILES["file"]["tmp_name"],
"./uploads/" . $_FILES["file"]["name"]);
echo "Stored in: " . "./uploads/" . $_FILES["file"]["name"];
}
}
}
else
{
echo "Invalid file";
}
?>

 

Link to comment
https://forums.phpfreaks.com/topic/90566-php-upload-script/#findComment-464379
Share on other sites

now I am confused, all I want to do is get this upload script to work

the developer says to use your own upload.php but as I can't get this to work maybe we could tweak his version ???

 

<?

$result = array();

if (!headers_sent() && isset($_FILES['image_file']) && ($log = fopen('./upload.log', 'a') ) )
{
	$file = $_FILES['image_file']['tmp_name'];
	$error = false;
	$size = false;

	if (!is_uploaded_file($file) || ($_FILES['image_file']['size'] > 2 * 1024 * 1024) )
	{
		$error = 'Please upload only files smaller than 2Mb!';
	}
	if (!$error && !($size = @getimagesize($file)))
	{
		$error = 'Please upload only images, no other files are supported.';
	}
	if (!$error && !in_array($size[2], array(1, 2, 3, 7,  ) )
	{
		$error = 'Please upload only images of type JPEG.';
	}
	if (!$error && ($size[0] < 25) || ($size[1] < 25))
	{
		$error = 'Please upload an image bigger than 25px.';
	}

	fputs($log, ($error ? 'FAILED' : 'SUCCESS') . ' - ' . gethostbyaddr($_SERVER['REMOTE_ADDR']) . ": {$_FILES[image_file][name]} - {$_FILES[image_file][size]} byte \n" );
	fclose($log);

	if ($error)
	{
		$result['result'] = 'failed';
		$result['error'] = $error;
	}
	else
	{
		$result['result'] = 'success';
		$result['size'] = "Uploaded an image ({$size['mime']}) with  {$size[0]}px/{$size[1]}px.";
	}

}
else
{
	$result['result'] = 'error';
	$result['error'] = 'Missing file or internal error!';
}

if (!headers_sent())
{
	header('Content-type: application/json');
}


echo json_encode($result);
?>

 

 

Link to comment
https://forums.phpfreaks.com/topic/90566-php-upload-script/#findComment-464410
Share on other sites

Thanks for everyones help with this

finally got it working  ;D

 

<?php
$uploaddir = '/usr/home/..................../'; // hidden for security reasons
$uploadfile = $uploaddir . basename($_FILES['image_file']['name']);
if (move_uploaded_file($_FILES['image_file']['tmp_name'], $uploadfile)) {
    echo "File Uploaded";
} else {
  	echo "Upload Failed!";
}
?>

 

I tried to add the basic validation to this and the upload now fails, anyone any idea's ???

 

<?php
$file_types = array("image/png","image/jpeg","image/gif");
if 
((in_array($_FILES["image_file"]["type"],$file_types))&&($_FILES["image_file"]["size"] 
> 20000))
{
$uploaddir = '/usr/home/virtuals/web/comedinewithus/admin/uploads/';
$uploadfile = $uploaddir . basename($_FILES["image_file"]["name"]);
if (move_uploaded_file($_FILES["image_file"]["tmp_name"], $uploadfile)) {
echo "File Uploaded";
}
} else {
echo "Upload Failed!";
}

?>

Link to comment
https://forums.phpfreaks.com/topic/90566-php-upload-script/#findComment-464855
Share on other sites

I now have the following and the upload still fails

 

<?php
$file_types = array("image/png","image/jpeg","image/gif");
if 
((in_array($_FILES["image_file"]["type"],$file_types))&&($_FILES["image_file"]["size"] 
< 20000))
{
$uploaddir = '/usr/home/virtuals/web/comedinewithus/admin/uploads/';
$uploadfile = $uploaddir . basename($_FILES["image_file"]["name"]);
if (move_uploaded_file($_FILES["image_file"]["tmp_name"], $uploadfile)) {
echo "File Uploaded";
}
} else {
echo "Upload Failed!";
}

?>

Link to comment
https://forums.phpfreaks.com/topic/90566-php-upload-script/#findComment-465284
Share on other sites

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.