help in php upload image ,rename for 150 c

Status
Not open for further replies.

nahsorhseda

Member
Messages
116
Reaction score
0
Points
16
below i have a script which can be used to upload images ,but the problem is i want the files to be renamed
for ex:if i have a file called "ab cd.jpg" ,i want to rename it to "ab_cd.jpg" or abcd.jpg i just want the spaces to dissappear .......

iam learning php and iam testing/working on a image editing script thats why i want the files to be renamed

here is the script please change it and post ......i mean the whole script from<?php to ?> please dont write half the script n post ....coz iam just a beginner....ill also pay you 100-150 credits for the work

here is the script....

PHP:
l;

<?php
if (($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/png")
|| ($_FILES["file"]["type"] == "image/vnd.wap.wbmp")
|| ($_FILES["file"]["type"] == "image/bmp")
|| ($_FILES["file"]["type"] == "image/pjpeg")
&& ($_FILES["file"]["size"] < 200000000000000))
  {
  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("./" . $_FILES["file"]["name"]))
      {
      echo $_FILES["file"]["name"] . " already exists. ";

      }
    else
      {
      move_uploaded_file($_FILES["file"]["tmp_name"],
      "./" . $_FILES["file"]["name"]);
      echo "Stored in: " . "image editor/" . $_FILES["file"]["name"];
echo"<br/>";


      }
    }
  }
else
  {
  echo "invalid file<br/>";

  }
?>


thnks in advance
 

Slothie

New Member
Messages
1,429
Reaction score
0
Points
0
PHP:
<?php
if (($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/png")
|| ($_FILES["file"]["type"] == "image/vnd.wap.wbmp")
|| ($_FILES["file"]["type"] == "image/bmp")
|| ($_FILES["file"]["type"] == "image/pjpeg")
&& ($_FILES["file"]["size"] < 200000000000000))
  {
  if ($_FILES["file"]["error"] > 0)
    {
    echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
    }
  else
    {
    echo "Upload: " . str_replace(' ','_',$_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("./" . $_FILES["file"]["name"]))
      {
      echo $_FILES["file"]["name"] . " already exists. ";

      }
    else
      {
      move_uploaded_file($_FILES["file"]["tmp_name"],
      "./" . str_replace(' ','_',$_FILES["file"]["name"]);
      echo "Stored in: " . "image editor/" . $_FILES["file"]["name"];
echo"<br/>";


      }
    }
  }
else
  {
  echo "invalid file<br/>";

  }
?>
 

Slothie

New Member
Messages
1,429
Reaction score
0
Points
0
PHP:
<?php

$fn = $_FILES["file"]["name"];
$fn = str_replace(" ","_",$fn);
if (($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/png")
|| ($_FILES["file"]["type"] == "image/vnd.wap.wbmp")
|| ($_FILES["file"]["type"] == "image/bmp")
|| ($_FILES["file"]["type"] == "image/pjpeg")
&& ($_FILES["file"]["size"] < 200000000000000))
  {
  if ($_FILES["file"]["error"] > 0)
    {
    echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
    }
  else
    {
    echo "Upload: " . $fn . "<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("./" . $fn))
      {
      echo $fn . " already exists. ";

      }
    else
      {
      move_uploaded_file($_FILES["file"]["tmp_name"],
      "./" . $fn);
      echo "Stored in: " . "image editor/" . $fn;
echo"<br/>";


      }
    }
  }
else
  {
  echo "invalid file<br/>";

  }
?>
 

nahsorhseda

Member
Messages
116
Reaction score
0
Points
16
actually there was a only a small mistake in your code
that you forgot to add an ")" to the code
now the code would be
"./" . str_replace(' ','_',$_FILES["file"]["name"]));
u get your 100 c
 
Status
Not open for further replies.
Top