我可以这样做,所以来自ipad的image.jpg被重命名为image_ [RANDOMNUMBER] .jpg

时间:2014-03-09 21:52:25

标签: php

我基本上想要改变剧本:D

posts.php :(要上传的页面)

<a href="http://photobookphotosharing.comoj.com/posts.php">
<img style="border:0;" src="/upload/viper/Photobook%20Logo%202.png" alt="HTML tutorial" width="250" height="250"></a></p>


<!DOCTYPE html>

<html>

    <head>

        <meta charset="UTF-8">

        <title>Photobook- Photo Sharing</title>

        <link rel="stylesheet" href="styles/main.css" />

    </head>

    <body>


            <p>Welcome <b>MCPCharlie</b> to photobook by <b><i>MCPCharlie!</b></i></p>

            <p>To get to your photo go to http://photobookphotosharing.comoj.com/Upload/USERNAME/FileName.FileFormat<p>

<b><p>For example http://photobookphotosharing.comoj.com/Upload/MCPCharlie/Tulips.jpg (for MCPCharlie's photo tulips)</p></b>

<p>

              Post your photo! :)

            </p>

<b>You cannot logout of the BETA snapshot, sorry</b>

<html>

<body>



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

enctype="multipart/form-data">

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

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

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

<input type="hidden" name="username" value="MCPCharlie" />

</form>

<h4>Featured:</h4>

<img src="/featured/Tulips.jpg" height="200" width="200">

<p>by <b><i>MCPCharlie</b></i></p>

<img src="/featured/2.jpg" height="400" width="400">

<p>by <b><i>[Beta Tester]</i> Swain24</b></p>

<p>To feature email mcpchalie@gmail.com with username and link</p>

</body>

</html>


    </body>

</html>
<script type='text/javascript'>(function () { var done = false; var script = document.createElement('script'); script.async = true; script.type = 'text/javascript'; script.src = 'https://widget.purechat.com/VisitorWidget/WidgetScript'; document.getElementsByTagName('HEAD').item(0).appendChild(script); script.onreadystatechange = script.onload = function (e) { if (!done && (!this.readyState || this.readyState == 'loaded' || this.readyState == 'complete')) { var w = new PCWidget({ c: '23594287-d4f4-414f-99c2-f85f49574bfb', f: true }); done = true; } }; })();</script>

upload_file.php :(处理器)

<?php
$allowedExts = array("gif", "jpeg", "jpg", "png");
$user = $_POST['username'];
$temp = explode(".", $_FILES["file"]["name"]);
$extension = end($temp);
if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/jpg")
|| ($_FILES["file"]["type"] == "image/pjpeg")
|| ($_FILES["file"]["type"] == "image/x-png")
|| ($_FILES["file"]["type"] == "image/png"))
&& in_array($extension, $allowedExts))
  {
  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/"  . $user . "/" . $_FILES["file"]["name"]))
      {
      echo $_FILES["file"]["name"] . " already exists. ";
      }
    else
      {
if (!file_exists("upload/" . $user . "/"))
      {
        mkdir("upload/" . $user . "/", 0777);
      }
      move_uploaded_file($_FILES["file"]["tmp_name"],
      "upload/" . $user . "/" . $_FILES["file"]["name"]);
header('location: upload/' . $user . "/");
      }
    }
  }
else
  {
  echo "Invalid file";
  }
?>
<input type="hidden" name="username" value="<?php echo htmlentities($_SESSION['username']); ?>" />
<p>to get to your file go to WEBSITEADRESS/upload/FILENAME.FILETYPE</p> 
<p><b>(FILENAME AND FILETYPE SHOWN AFTER UPLOAD)</p></b>

0 个答案:

没有答案