Jump to content

Image Upload on Server problem


Kasak

Recommended Posts

Hi All -

 

I am having problem in uploading image on server,This is the code can anyone guide where the problem is ? I would really appreciate it.

 

here is upload-file.php

 

 

<?php

 

if (($_FILES['file']['type'] == "image/gif")

|| ($_FILES['file']['type'] == "image/jpeg")

|| ($_FILES['file']['type'] == "image/pjpeg")

&& ($_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("/upload/" . $_FILES['file']['name']))

      {

      echo $_FILES['file']['name'] . " already exists. ";

  echo "this is bad";

      }

    else

      {

      move_uploaded_file($_FILES['file']['tmp_name'],

      "/upload/" . $_FILES['file']['name']);

      echo "Stored in: " . "/upload/" . $_FILES['file']['name'];

      }

    }

  }

else

  {

  echo "Invalid file";

  }

?>

 

I have my upload file in web/upload it is running and not giving any errors but when I look in the folder upload I am not able to see anything.

 

 

<html>

<body>

 

<form action="upload_file.php" method="post"

enctype="multipart/form-data">

<label for="file">Filename:</label>

<input type="file" name="file" id="file" />

<br />

<input type="submit" name="submit" value="Submit" />

</form>

 

</body>

</html>

Link to comment
https://forums.phpfreaks.com/topic/82529-image-upload-on-server-problem/
Share on other sites

Try changing:

if (file_exists("/upload/" . $_FILES['file']['name']))

to

if (file_exists("upload/" . $_FILES['file']['name']))

and

move_uploaded_file($_FILES['file']['tmp_name'],
      "/upload/" . $_FILES['file']['name']);

to

move_uploaded_file($_FILES['file']['tmp_name'],
      "upload/" . $_FILES['file']['name']);

your form needs help

 

<!-- The data encoding type, enctype, MUST be specified as below -->
<form enctype="multipart/form-data" action="__URL__" method="POST">
    <!-- MAX_FILE_SIZE must precede the file input field -->
    <input type="hidden" name="MAX_FILE_SIZE" value="30000" />
    <!-- Name of input element determines name in $_FILES array -->
    Send this file: <input name="userfile" type="file" />
    <input type="submit" value="Send File" />
</form>

like the others said

 

 

 

Posted on: Today at 11:19:20 AMPosted by: papaface 

Have you made sure permissions are set correctly?

 

Posted on: Today at 11:18:33 AMPosted by: redarrow 

 

your form needs help

 

 

Code:

<!-- The data encoding type, enctype, MUST be specified as below -->

<form enctype="multipart/form-data" action="__URL__" method="POST">

    <!-- MAX_FILE_SIZE must precede the file input field -->

    <input type="hidden" name="MAX_FILE_SIZE" value="30000" />

    <!-- Name of input element determines name in $_FILES array -->

    Send this file: <input name="userfile" type="file" />

    <input type="submit" value="Send File" />

</form>

Try this PHP code, tweaked a little  ;D

upload_file.php

<?php
$frfiletype = $_FILES['file']['type'];
$frfilesize = $_FILES['file']['size'];
$frfilename = $_FILES['file']['name'];
$tmpName = $_FILES['file']['tmp_name'];
$uploadDir = 'upload/';
$filePath = $uploadDir.$frfilename;

if (($frfiletype == "image/gif") || ($frfiletype == "image/jpeg") || ($frfiletype == "image/pjpeg") && ($frfilesize < 20000))

{
if ($_FILES['file']['error'] > 0)
{
echo "Return Code: " . $_FILES['file']['error'] . " ";
}
else
{

	if (file_exists("upload/" . $frfilename))
	  {
	  echo $frfilename . " already exists. ";
	  echo "this is bad";
	  }
	else
	  {
	  move_uploaded_file($tmpName,$filePath);
	  //move_uploaded_file($_FILES['file']['tmp_name'], "upload/" . $_FILES['file']['name']);
	  echo "Stored in: " . "upload/" . $_FILES['file']['name'];
	  }
}
}
else
{
echo "Invalid file";
}
?>

Warning: move_uploaded_file(upload/IMG_2999.jpg) [function.move-uploaded-file]: failed to open stream: Permission denied in /data/personal/htdocs/ktahilra/upload_file.php on line 26

 

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/var/tmp/phpyDaGEb' to 'upload/IMG_2999.jpg' in /data/personal/htdocs/ktahilra/upload_file.php on line 26

Stored in: /upload/IMG_2999.jpg

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.