Jump to content

[SOLVED] upload script


lewis987

Recommended Posts

ok i have an upload script:

 

<?php
if (($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/pjpeg")
&& ($_FILES["file"]["size"] < 2000000))
  {
  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("upload/" . $_FILES["file"]["name"]))
      {
      echo $_FILES["file"]["name"] . " already exists. ";
      }
    else
      {
      move_uploaded_file($_FILES["file"]["tmp_name"],
      "upload/" . $_FILES["file"]["name"]);
      echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
      }
    }
  }
else
  {
  echo "Invalid file";
  }
?>

 

however, when i test it, it fails straight away, anyone got a remedy?

 

thanks!

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

CHMOD 766 for upload dir no no no 777 is securety risk, will allow to execute the file!!!!

 

Make sure the upload is above the dir you running the script in, if not use absolute path!

/home/usernamer/etc...

or you have your own server maybe

C:\\ not sure

Use enviromental variable to look up your documer root! $Server['document_root'] check syntax

www.php.net

Link to comment
https://forums.phpfreaks.com/topic/50475-solved-upload-script/#findComment-248022
Share on other sites

Two issues...

 

1) You needed brackets around your image type condition.... (gif || jpeg) && filesize....

2) You had pjpeg instead of jpeg

 

<?php
if ((($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == "image/jpeg")) && ($_FILES["file"]["size"] < 2000000)) {
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("upload/" . $_FILES["file"]["name"])) {
		echo $_FILES["file"]["name"] . " already exists. ";
	} else {
		move_uploaded_file($_FILES["file"]["tmp_name"], "upload/" . $_FILES["file"]["name"]);
		echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
	}
}
} else {
echo "Invalid file";
}
?>

Link to comment
https://forums.phpfreaks.com/topic/50475-solved-upload-script/#findComment-248599
Share on other sites

<?php

echo "<pre>";
print_r($_FILES['file']);  // Print this and post the o/p here

if (($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/pjpeg")
&& ($_FILES["file"]["size"] < 2000000))
  {
  if ($_FILES["file"]["error"] > 0)
    {
..........
..........
.........
?>

Link to comment
https://forums.phpfreaks.com/topic/50475-solved-upload-script/#findComment-248713
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.