如何使用带有原始文件名的文本框的回显复制

发布于 2024-12-29 19:28:13 字数 2221 浏览 0 评论 0原文

该脚本的步骤。

  1. 在文本框中插入链接(如rapidleech),但这里我有2个文本框

  2. 通过回显复制上传文件(远程链接) ,我的服务器)(这不起作用)

  3. 在文本框中打印文件的HTML信息(我想在这里我有错误)

注意 - 仅图像信息 重要

提示 - 如何获取原始文件名并保存在服务器上?

HTML

<html>
<body>

<form action="upload_file.php" method="post" enctype="multipart">
<label for="file">thumb link : </label>
<input type="text" name="file" id="file" />
<br />
<label for="file2">image link : </label>
<input type="text" name="file2" id="file2" />
<br />
<input type="submit" name="submit" value="Submit" />
</form>

</body>
</html>

PHP

<?php
define ( 'IMAGE_DIR', 'img/' );
define ( 'THUMB_DIR', 'thumb/' );
$thumblink = "file1";
$imglink = "file2";
$printhtml = "printhtml";
$filesize = "size";
$filesizelimit = "limit";
$printtxt = "<center><img src=\"{$thumblink}\"/><br/>
            <a href=\"{$imglink}\" target=\"_blank\">download image</a> /
            {$filesize} <br/></center>";
// here is dont work show error
// error   syntax error, unexpected T_STRING
echo copy("{$thumblink}", THUMB_DIR . '["name"]');
echo copy("{$imglink}", IMAGE_DIR . '["name"]');
//

if ((($_FILES["file2"]["type"] == "image/gif")
|| ($_FILES["file2"]["type"] == "image/jpeg")
|| ($_FILES["file2"]["type"] == "image/pjpeg"))
&& ($_FILES["file2"]["size"] < 2000000))
  {
  if ($_FILES["file2"]["error"] > 0)
    {
    echo "Error: " . $_FILES["file2"]["error"] . "<br />";
    }
  else
    {
    echo "Upload: " . $_FILES["file2"]["name"] . "<br />";
    echo "Type: " . $_FILES["file2"]["type"] . "<br />";
    echo "Size: " . ($_FILES["file2"]["size"] / 1024) . " Kb<br />";
    echo "thumb in: " . $_FILES["file1"][THUMB_DIR];
    echo "image in: " . $_FILES["file2"][IMAGE_DIR];


    echo "<center><img src=\"{$thumblink}\"/><br/>
            <a href=\"{$imglink}\" target=\"_blank\">download image</a> /
             {$filesize} <br/></center>";
    }
  }
else
  {
  echo "Invalid file";
  }
?>

Steps of this script.

  1. Insert link in text box (like rapidleech) but here I have 2 text box

  2. Upload files via echo copy (remote link, my server) (This doesn't work)

  3. Print files' HTML info in a textbox (I think here I have an error)

note - Just image information important

note - How can get orginal filename and save on server?

HTML

<html>
<body>

<form action="upload_file.php" method="post" enctype="multipart">
<label for="file">thumb link : </label>
<input type="text" name="file" id="file" />
<br />
<label for="file2">image link : </label>
<input type="text" name="file2" id="file2" />
<br />
<input type="submit" name="submit" value="Submit" />
</form>

</body>
</html>

PHP

<?php
define ( 'IMAGE_DIR', 'img/' );
define ( 'THUMB_DIR', 'thumb/' );
$thumblink = "file1";
$imglink = "file2";
$printhtml = "printhtml";
$filesize = "size";
$filesizelimit = "limit";
$printtxt = "<center><img src=\"{$thumblink}\"/><br/>
            <a href=\"{$imglink}\" target=\"_blank\">download image</a> /
            {$filesize} <br/></center>";
// here is dont work show error
// error   syntax error, unexpected T_STRING
echo copy("{$thumblink}", THUMB_DIR . '["name"]');
echo copy("{$imglink}", IMAGE_DIR . '["name"]');
//

if ((($_FILES["file2"]["type"] == "image/gif")
|| ($_FILES["file2"]["type"] == "image/jpeg")
|| ($_FILES["file2"]["type"] == "image/pjpeg"))
&& ($_FILES["file2"]["size"] < 2000000))
  {
  if ($_FILES["file2"]["error"] > 0)
    {
    echo "Error: " . $_FILES["file2"]["error"] . "<br />";
    }
  else
    {
    echo "Upload: " . $_FILES["file2"]["name"] . "<br />";
    echo "Type: " . $_FILES["file2"]["type"] . "<br />";
    echo "Size: " . ($_FILES["file2"]["size"] / 1024) . " Kb<br />";
    echo "thumb in: " . $_FILES["file1"][THUMB_DIR];
    echo "image in: " . $_FILES["file2"][IMAGE_DIR];


    echo "<center><img src=\"{$thumblink}\"/><br/>
            <a href=\"{$imglink}\" target=\"_blank\">download image</a> /
             {$filesize} <br/></center>";
    }
  }
else
  {
  echo "Invalid file";
  }
?>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

伴随着你 2025-01-05 19:28:13

PHP 常量不能插入到这样的字符串中 - PHP 无法知道您正在使用常量,而不仅仅是一些看起来像常量的文本:

请注意更改:

echo copy("{$thumblink}", THUMB_DIR . '["name"]');

echo "image in: " . $_FILES["file2"][IMAGE_DIR];

PHP constants cannot be inserted into a string like that - PHP has no way to know that you're using a constant, and not just some text that happens to look like a constant:

Note the changes:

echo copy("{$thumblink}", THUMB_DIR . '["name"]');

echo "image in: " . $_FILES["file2"][IMAGE_DIR];
逆光下的微笑 2025-01-05 19:28:13

这是行不通的:

echo print "<center>...";

你必须选择 :P echo 或 print :) 否则,如果 print() 返回 TRUE,它将回显“...”,后跟 1。这就是您要找的吗?

另外:

echo copy("{$thumblink}","THUMB_DIR["name"]");
echo copy("{$imglink}","IMAGE_DIR["name"]");

注意到引号是如何相互妨碍的吗?和 THUMB_DIR & IMAGE_DIR 是常量,而不是数组。你到底想在这里做什么?

此外,copy() 返回一个布尔值。为什么要回声呢?如果 copy() 返回 FALSE,则不会显示任何内容。

This can't work:

echo print "<center>...";

You've gotta chose :P Either echo, or print :) Or else, it will echo "..." followed by a 1 if print() returns TRUE. Is that what you are looking for ?

Also:

echo copy("{$thumblink}","THUMB_DIR["name"]");
echo copy("{$imglink}","IMAGE_DIR["name"]");

Notice how the quotes get in the way of each other ? And THUMB_DIR & IMAGE_DIR are constants, and not arrays. What do you want do here exactly ?

Also, copy() returns a boolean value. Why echo it ? It will show nothing if copy() returns FALSE.

安静 2025-01-05 19:28:13

请将您的 define 更改为:

$IMAGE = array('IMAGE_DIR' => 'img/',
        'THUMB_DIR' => 'thumb/');

那么

$new_file_name = "new.gif";
    echo copy("{$thumblink}", $IMAGE['THUMB_DIR']$new_file_name);
    echo copy("{$imglink}", $IMAGE['IMAGE_DIR'].$new_file_name);

仍然不明白为什么要回显这些?..

您还需要更改原始文件名:

$imglink = "file2.gif";

please change your define to:

$IMAGE = array('IMAGE_DIR' => 'img/',
        'THUMB_DIR' => 'thumb/');

Then

$new_file_name = "new.gif";
    echo copy("{$thumblink}", $IMAGE['THUMB_DIR']$new_file_name);
    echo copy("{$imglink}", $IMAGE['IMAGE_DIR'].$new_file_name);

still don't understand why should you echo these?..

you also need to change original file name:

$imglink = "file2.gif";
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文