Jump to content

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

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.