Reputation: 71
I am currently working a code that will upload the contents of a textarea as .html file into a folder named uploads. I would like for the php script to run when the user presses share.
<a id="wshare" class="btn">Share</a>
<textarea id="icontent" placeholder="Enter your content here." name="mas" rows="15" class="content"></textarea>
<?php
error_reporting(0);
if(isset($_FILES['image'])){
$errors= array();
$file_name = rand(5, 1000000);
$file_size =$_FILES['image']['size'];
$file_tmp =$_FILES['image']['tmp_name'];
$file_type=$_FILES['image']['type'];
$file_ext=strtolower(end(explode('.',$_FILES['image']['name'])));
$expensions= array("html");
if(in_array($file_ext,$expensions)=== false){
$errors[]="Only Html Files can be uploaded!";
}
if($file_size > 2097152){
$errors[]='Sorry,Looks Like Your File Is Larger Than 2MB =(';
}
if(empty($errors)==true){
move_uploaded_file($file_tmp,"uploads/".$file_name);
echo "Success-Link: uploads/" .$file_name;
}else{
print_r($errors);
}
}
?>
Upvotes: 1
Views: 74
Reputation: 460
I guess you know that php and javascript aren't executed at the same time not the same "place" and cant be used together as you seems like you're intenting.
IMO you should ask the user for a filename at the moment your form get submitted, fill a hidden input field with the answer, then combine both of the values (textarea + hidden input field) in php
Upvotes: 1