Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/287.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 带有图像上传器的HTML文本区域_Php_Javascript_Html_Ajax_Textarea - Fatal编程技术网

Php 带有图像上传器的HTML文本区域

Php 带有图像上传器的HTML文本区域,php,javascript,html,ajax,textarea,Php,Javascript,Html,Ajax,Textarea,我有一个可以使用的评论框,但我想添加上传图像的选项。然后,图像将显示在底部的文本区域中,就像facebook一样 页面member-index.php上的代码是: <form action="../login/comment-exec.php" method="POST"> <textarea name="comment" id="feeds" rows="5" ></textarea> <input type="hidden" value=

我有一个可以使用的评论框,但我想添加上传图像的选项。然后,图像将显示在底部的文本区域中,就像facebook一样

页面member-index.php上的代码是:

 <form action="../login/comment-exec.php" method="POST">
    <textarea name="comment" id="feeds" rows="5"  ></textarea>
<input type="hidden" value="<?php $_SESSION['SESS_MEMBER_ID']?>" name="members_id" />
    <input type="submit"  class="postbutton" name="submit" value="Post" />
    </form>


不确定是否将上传数据嵌套到文本区域,但这里有一组很好的图像/文件上传脚本可能会有所帮助


您可以始终对此脚本运行一个ajax调用,将上载结果加载到文本区域……或者在文本区域下方运行一个div,向用户显示他们上载的内容。希望它有帮助……

您需要在表单中添加以下内容:

$allowed_filetypes = array('.jpg','.gif','.bmp','.png'); // These will be the types of file that will pass the validation.
$max_filesize = 9999999999; // Maximum filesize in BYTES - SET IN to a low number for small files
$upload_path = './uploads/'; // The place the files will be uploaded to (currently a 'files' directory).

$filename = $_FILES['imagefile']['name']; // Get the name of the file (including file extension).
$ext = substr($filename, strpos($filename,'.'), strlen($filename)-1); // Get the extension from the filename.

// Check if the filetype is allowed, if not DIE and inform the user.
if(!in_array($ext,$allowed_filetypes))
die('The file you attempted to upload is not allowed.');

// Now check the filesize, if it is too large then DIE and inform the user.
if(filesize($_FILES['imagefile']['tmp_name']) > $max_filesize)
die('The file you attempted to upload is too large.');

// Check if we can upload to the specified path, if not DIE and inform the user.
if(!is_writable($upload_path))
die('You cannot upload to the specified directory, please CHMOD it to 777.');

// Upload the file to your specified path.
if(move_uploaded_file($_FILES['imagefile']['tmp_name'],$upload_path . $filename))

// Echo success and the uploaded file.
echo 'Your file upload was successful, view the file <img src="' . $upload_path . $filename . '" title="Anything you want">'; // It worked.
else
echo 'There was an error during the file upload. Please try again.'; // It failed

// rest of your code to be placed below
enctype=“多部分/表单数据”
即:

然后在表单处理程序中的某个位置执行此操作:

$allowed_filetypes = array('.jpg','.gif','.bmp','.png'); // These will be the types of file that will pass the validation.
$max_filesize = 9999999999; // Maximum filesize in BYTES - SET IN to a low number for small files
$upload_path = './uploads/'; // The place the files will be uploaded to (currently a 'files' directory).

$filename = $_FILES['imagefile']['name']; // Get the name of the file (including file extension).
$ext = substr($filename, strpos($filename,'.'), strlen($filename)-1); // Get the extension from the filename.

// Check if the filetype is allowed, if not DIE and inform the user.
if(!in_array($ext,$allowed_filetypes))
die('The file you attempted to upload is not allowed.');

// Now check the filesize, if it is too large then DIE and inform the user.
if(filesize($_FILES['imagefile']['tmp_name']) > $max_filesize)
die('The file you attempted to upload is too large.');

// Check if we can upload to the specified path, if not DIE and inform the user.
if(!is_writable($upload_path))
die('You cannot upload to the specified directory, please CHMOD it to 777.');

// Upload the file to your specified path.
if(move_uploaded_file($_FILES['imagefile']['tmp_name'],$upload_path . $filename))

// Echo success and the uploaded file.
echo 'Your file upload was successful, view the file <img src="' . $upload_path . $filename . '" title="Anything you want">'; // It worked.
else
echo 'There was an error during the file upload. Please try again.'; // It failed

// rest of your code to be placed below
$allowed_filetypes=array('.jpg'、'.gif'、'.bmp'、'.png');//这些将是通过验证的文件类型。
$max_filesize=9999999;//最大文件大小(以字节为单位)-对于小文件,将其设置为较低的数字
$upload_path='。/uploads/';//文件将上载到的位置(当前为“文件”目录)。
$filename=$_文件['imagefile']['name'];//获取文件名(包括文件扩展名)。
$ext=substr($filename,strpos($filename,“.”),strlen($filename)-1);//从文件名中获取扩展名。
//检查文件类型是否允许,如果不允许,请通知用户。
如果(!in_数组($ext,$allowed_文件类型))
die('不允许您尝试上载的文件');
//现在检查文件大小,如果文件太大,请退出并通知用户。
if(文件大小($\u FILES['imagefile']['tmp\u name'])>$max\u文件大小)
die('您尝试上载的文件太大');
//检查是否可以上传到指定的路径,如果没有死,通知用户。
如果(!是可写的($upload\u path))
die('您无法上载到指定目录,请将其CHMOD到777');
//将文件上载到指定路径。
如果(移动上传的文件($\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\$filename))
//回显成功并上传文件。
echo“您的文件上载成功,请查看文件”;//成功了。
其他的
echo“文件上载过程中出现错误。请再试一次。“;//它失败了
//其余代码将放在下面
DB注意:为了在数据库中插入上传的文件或对其的引用,可能需要在此过程中重命名图像文件本身,或为其设置唯一的ID。我在这个领域没有任何专业知识,但我知道你的记录必须是独一无二的


例如,人们从iPod Touch或iPhone等上传JPG。图像的默认名称为
image.JPG
。任何从这些设备上传图像且未重命名的人将自动覆盖先前上传的
image.jpg
;值得深思。

如果你像facebook一样在中发送文件,你就不会希望在发送表单的同时发送文件。当你将图片上传到facebook(或大多数流行网站)时,它实际上会在提交表单的文本部分之前将图片上传到他们的服务器

有几种方法可以做到这一点,将其添加到代码中最简单的方法是使用HTML5 FileReader类(),它所做的是加载文件内容的base64编码版本,将其设置为表单中的字段,然后在另一端构造文件



我知道的最佳上传文件教程:我不太清楚为什么要使用FileReader。这可能会为应用程序增加大量额外的客户端处理时间,具体取决于文件的大小。这确实不是FileReader的理想用例。我也不太清楚为什么你不想在同一个请求中发送文件和评论。你能详细介绍一下你的答案吗?我给了他一个拖放支持的起点,并在发送评论之前上传了图片。FileReader与拖放支持无关。此外,没有任何理由说明你不能在同一个请求中发送文件和评论,即使有DnD支持。谢谢你,它成功了@特里斯坦麦克史密斯不客气,干杯!