i am having an issue with a component of a website i am designing. i am having trouble uploading files through the page... PHP is capped at 32mb. the file system i am working on, i expect files in the neighbourhood of 500mb. Most around 250-300... but want that buffer. i have heard of direct ftp uploads through. I do believe this is the direction i need to go in:
<?php
// connect and login to FTP server
$ftp_server = "ftp.example.com";
$ftp_conn = ftp_connect($ftp_server) or die("Could not connect to $ftp_server");
$login = ftp_login($ftp_conn, $ftp_username, $ftp_userpass);
$file = "localfile.txt";
// upload file
if (ftp_put($ftp_conn, "serverfile.txt", $file, FTP_ASCII))
{
echo "Successfully uploaded $file.";
}
else
{
echo "Error uploading $file.";
}
// close connection
ftp_close($ftp_conn);
?>
this would be my html and php.
<?php
include_once(db_conx.php);
?><?php
error_reporting(E_ALL);
if(isset($_POST['submit'])){
$name = $_FILES['file']['name'];
$temp = $_FILES['file']['tmp_name'];
move_uploaded_file($temp,"vids/".$file);
$url = "http://x-webb.com/vids/.$file";
}
?>
<!DOCTYPE HTML>
<html>
<head>
<title>video uploader</title>
<meta name="" content="">
</head>
<body>
<h1>Video Uploader</h1>
<form method="POST" enctype="multipart/form-data">
Video: <br>
<input type="file" name="name"><br />
<label for="title">Title:</label><br>
<input type="text" name="title" id="title" placeholder="required" ><br>
<label for="description">Description:</label><br>
<textarea name="description" id="description" placeholder="required" ></textarea><br>
<label for="tags">Tags:</label><br>
<textarea name="tags" id="tags" placeholder="required" ></textarea><br>
<input type="submit" value="upload">
</form>
</body>
</html>
i just cant seem to put the 2 together. I have the ftp_conx.php file for the ftp server..checked out ok... no errors.
i have been programing for a hobby for about 18 months with html and CSS... about 2 months with ajax and php. my built pages are
autodude666.com/network
x-webb.com
current project, where i wish to place this code, is :
http://x-webb.com
ANY help would be GREATLY appreciated. TY in advance.
You can increase the maximum upload size in PHP. Adjust in php.ini:
upload_max_filesize = 500M
post_max_size = 500M
Additionally, you should consider the amount of time it takes a user to upload a 500MB file and set the maximum time limit accordingly.
I see that you're using Apache from the server signature header of the site you provided, but for anyone else who might be running nginx + php-fpm, you also have to increase the value of client_max_body_size in the http block of your nginx config or you'll see 413 errors.
Related
This question already has answers here:
PHP ftp_put fails
(2 answers)
Closed 18 days ago.
I'm using a script to upload file via php script to my ftp server.
The connection is ok but every time i try to upload files it says:
Error uploading file! Please try again later.
so it seems that there is something wrong in the script.
Directory destination is mydomain/test/upload/
and the script is into: mydomain/test/index.php
Anyone of you can help me to understand?
// ftp settings
$ftp_hostname = 'xxxx'; // change this
$ftp_username = 'xxxx'; // change this
$ftp_password = 'xxxx'; // change this
$remote_dir = '/upload/'; // change this
$src_file = $_FILES['srcfile']['name'];
if ($src_file!='')
{
// remote file path
$dst_file = $remote_dir . $src_file;
// connect ftp
$ftpcon = ftp_connect($ftp_hostname) or die('Error connecting to ftp server...');
// ftp login
$ftplogin = ftp_login($ftpcon, $ftp_username, $ftp_password);
// ftp upload
if (ftp_put($ftpcon, $dst_file, $src_file, FTP_ASCII))
echo 'File uploaded successfully to FTP server!';
else
echo 'Error uploading file! Please try again later.';
// close ftp stream
ftp_close($ftpcon);
}
else
header('Location: index.php');
and the index file is:
<!DOCTYPE html>
<html>
<head>
<title>Upload Files to FTP Server in PHP</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0" >
<link href="css/bootstrap.css" rel="stylesheet" type="text/css" />
</head>
<body>
<br/>
<div class="container">
<div class="col-xs-8 col-xs-offset-2 well" style="background:none;">
<form action="ftp_upload.php" method="post" enctype="multipart/form-data">
<legend>Please Choose File to Upload</legend>
<div class="form-group">
<input type="file" name="srcfile" />
</div>
<div class="form-group">
<input type="submit" name="submit" value="Upload File to FTP Server" class="btn btn-warning"/>
</div>
</form>
</div>
</div>
</body>
</html>
I want to have uploaded file into the upload folder:
mydomain/test/upload/
Either the source file is incorrect, or your FTP sits behind a firewall.
If it's behind a firewall, try this ftp-pasv
Recently, I have created an upload form in which users can upload their files to a remote FTP server. Until now, everything is going well. However, I have a problem.
I want to make sure that when the user his image is uploaded to the remote FTP server, the image will be displayed immediately on the website. How can I do this? This question has been asked a lot on Stack Overflow. Yet there is a difference. In most cases, the individual wanted to download a specific file from the remote FTP server. This is not the case with me. I want to make sure that the user sees the file he uploaded displayed on the site.
My php code for uploading a file to the remote FTP server:
<?php
if ( empty( $_FILES['file'] ) ) {
?>
<html>
<head>
</head>
<body>
<form action="" enctype="multipart/form-data" method="post">
<input name="file" type="file"/>
<br>
<input name="submit" type="submit" value="Upload uw album" />
</form>
</body>
</html>
<?php
return;
} else {
?>
<html>
<head>
</head>
<body>
<form action="" enctype="multipart/form-data" method="post">
<input name="file" type="file"/>
<br>
<input name="submit" type="submit" value="Upload uw album" />
</form>
</body>
</html>
<?php
}
$ftp_server = "myserver";
$ftp_user_name = "myuser";
$ftp_user_pass = "mypass";
$source_file = $_FILES['file']['tmp_name'];
$destination_folder = "/public_html/wp/wp-content/plugins/AbonneerProgrammas/Albums";
$destination_file = $destination_folder . "/" . basename($_FILES['file']['name']);
$conn_id = ftp_connect($ftp_server);
// login with username and password
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
ftp_pasv($conn_id, true);
// check connection
if ((!$conn_id) || (!$login_result)) {
echo "Het spijt ons, er is momenteel geen connectie met de server.";
//echo "Attempted to connect to $ftp_server for user $ftp_user_name";
exit;
} else {
//echo "upload is gelukt";
}
// upload the file
$upload = ftp_put($conn_id, $destination_file, $source_file, FTP_BINARY);
// check upload status
if (!$upload) {
//
} else {
?>
<meta http-equiv="refresh" content="0; url=https://radioprogrammabank.nl/wp/upload-album/?name=<?php echo urlencode(basename($_FILES['file']['name']));?>">
<?php
echo "".htmlspecialchars($source_file)."";
header('Content-Type: application/octet-stream');
echo file_get_contents('ftp://username:password#ftp.example.com/path/' . $_GET["file"]);
echo "upload is gelukt";
}
// close the FTP stream
ftp_close($conn_id);
?>
Once the FTP upload succeeds, you need to redirect user's browser to a viewer page.
header("Location: view.php?name=".urlencode(basename($_FILES['file']['name'])));
In the view.php, use the code from your examples to "download a specific file from the remote FTP server". Or see List and download clicked file from FTP.
Note that for the Location header to work, you cannot output anything before – so no echo and no HTML code.
But as you do not have a standalone PHP code, but you executed it from within some WordPress plugin, the WordPress will have already outputted some HTML headers before your code even starts. So the redirect won't work.
There's a question on this on the WordPress development Stack Exchange:
wp_redirect() not working in Insert PHP plugin in WordPress.
And you have asked another one:
Error: “Cannot modify header information”
Or as a lame hack, you can try meta redirect:
<meta http-equiv="refresh" content="0; url=view.php?name=<?php echo urlencode(basename($_FILES['file']['name']));?>">
I'm trying to upload an xml file using an Android app I developed.
To do this, I used a free hosting space, and it works great. But now, I want to upload files to one of my pc's folders, using xampp as a web server.
The problem is that when I try to upload files here something goes wrong.
I am sure my php code is good, because it works with the hosting service I have my website on, so I only changed the path, as you can see below.
For hosting service:
<?php
if (is_uploaded_file($_FILES['transactions']['tmp_name'])) {
$uploads_dir = '/membri/cendav/gestione_magazzino/ExportData/';
$tmp_name = $_FILES['transactions']['tmp_name'];
$pic_name = $_FILES['transactions']['name'];
move_uploaded_file($tmp_name, $uploads_dir.$pic_name);
}
else{
echo "File not uploaded successfully.";
}
?>
Now, the code for xampp, which is the same:
<?php
if (is_uploaded_file($_FILES['transactions']['tmp_name'])) {
$uploads_dir = 'exportdata/';
$tmp_name = $_FILES['transactions']['tmp_name'];
$pic_name = $_FILES['transactions']['name'];
move_uploaded_file($tmp_name, $uploads_dir.$pic_name);
}
else{
echo "File not uploaded successfully.";
}
?>
As you can see, I only changed the $uploads_dir. The path from where I access the file upload.php, from my application http://10.0.0.202:1024/Warepad/.
I also changed the permissions of the exportdata/ folder, to everyone, but it still doesn't work.
P.S. I know there's a ton of these issues, but I still can't find what the problem is.
try this:
<form action="fileupload.php" method="post" enctype="multipart/form-data">
<label for="file">Filename:</label>
<input type="file" name="file" id="file" />
<br />
<input type="submit" name="submit" value="Submit" />
</form>
So, now it seems to work. It's strange, because the file upload.php is the same, and I haven't changed anything else!
?php
if (is_uploaded_file($_FILES['transactions']['tmp_name'])) {
$uploads_dir = 'exportdata/';
$tmp_name = $_FILES['transactions']['tmp_name'];
$pic_name = $_FILES['transactions']['name'];
move_uploaded_file($tmp_name, $uploads_dir.$pic_name);
}
else{
echo "File not uploaded successfully.";
}
?>
The Android app, now, is able to upload file correctly, but if I try to upload from an html form, it still doesn't work.
Here's the html code:
<html>
<head>
<title>Upload</title>
<meta charset="utf-8">
</head>
<body>
<form action="upload.php" method="post">
<input type="hidden" name="MAX_FILE_SIZE" value="30000">
Invia questo file: <input name="transactions" type="file">
<input type="submit" value="Invia File">
</form>
</body>
</html>
I am using Heroku and their S3 addon - "Bucketeer".
I have this working and I can upload images no problem. The thing is I don't care about uploading images. My app deals with uploading MP3s (nothing sinister - it's a web app for local bands).
I can't upload MP3s. It doesn't error out or anything, it's just that files don't end up in S3 - whereas images uploaded exactly the same way, do.
Editing to add - It's not a file type issue as I tested by uploading a very small mp3 file and this worked great.
Code below:
<form class="form" action="../model/process-track-upload.php" method="post" enctype="multipart/form-data">
<div class="row">
<div class="col-xs-12 col-sm-4">
<div class="dashboard-widget">
<h3>Add a song to your collection</h3>
<input class="input" type="text" name="trackname" placeholder="Track Name" required/>
<input class="input-margin" name="userfile" type="file">
<input type="hidden" name="userID" value="<?php echo $userID ?>" />
<button class="btn btn-large btn-block " type="submit" name="btn-upload">upload</button>
</div>
</div>
</form>
And the backend code:
require('../vendor/autoload.php');
$s3 = Aws\S3\S3Client::factory();
$bucket = getenv('S3_BUCKET')?: die('No "S3_BUCKET" config var in found in env!');
if($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_FILES['userfile']) && $_FILES['userfile']['error'] == UPLOAD_ERR_OK && is_uploaded_file($_FILES['userfile']['tmp_name'])) {
try {
$upload = $s3->upload($bucket, $_FILES['userfile']['name'], fopen($_FILES['userfile']['tmp_name'], 'rb'), 'public-read');
?>
<p>Upload successful :)</p>
<?php } catch(Exception $e) { ?>
<p>Upload error :(</p>
<?php } }
The answer to this question lay in default php settings.
HOWEVER as I was using Heroku, I didn't have access to the php.ini file.
So the answer was to create a .users.ini file which is like a user created override of the php.ini.
In that file I just set the following params:
upload_max_filesize = 15M
post_max_size = 15M
max_input_time = 0
LimitRequestBody 0
After this I was good to go!
I have some forms in php that upload data into a mysql database. I have already tested on a localhost server with xampp, but when I upload my files into my host ftp, the forms do not work. I think it has something to do with the fact that I put this file and also the "connect.php" file under password restriction, and that has something to do with the file permissions. I've already granted permission to the user of the database and permission to the file and I also had tried without the password protection, but the result is the same.
So I start to experiment a little and I figured out that the image uploads fine into the database but the other inputs don't, neither the "header" input nor the "article" textarea... knowing that, I tried to "echo out" these input results but none of them show something unless the image input. I came to the conclusion that my form is sending empty data. Can someone make suggestions as to what is happening and how to fix it? Here's my code:
<html>
<head>
<meta charset="UTF-8">
<title>Untitled Document</title>
</head>
<body>
<div id="slider_upload">
<h1>Slider principal</h1>
<div class="forma">
<form action="sliderPrincipal.php" method="post" enctype="multipart/form-data">
<p><label for="header">Header</label>
<input type="text" id="header" name="header" /></p><br>
<input type="hidden" name="MAX_FILE_SIZE" value="1048576" />
<p><label for="fileupload">File to upload</label>
<input type="file" id="fileupload" name="fileupload" /></p><br>
<p><label for="article">article</label>
<textarea id="article" name="article" rows="26" style="width: 100%;" >Write here</textarea></p><br>
<button type="submit" name="submit" value"send">Upload File</button>
</form><br><br>
</div>
</div>
<div class="message">
<?php
$file_dir = "../uploaded";
if (isset($_POST['header'])){
$header = mysql_real_escape_string($_POST['header']);
$article = mysql_real_escape_string($_POST['article']);
}
foreach($_FILES as $file_name => $file_array){
//echo "path: ".$file_array['tmp_name']."<br />\n";
//echo "name: ".$file_array['name']."<br/>\n";
//echo "type: ".$file_array['type']."<br/>\n";
//echo "size: ".$file_array['size']."<br/><br/>\n";
//echo "encabezado ".$encabezado;
if(is_uploaded_file($file_array['tmp_name'])){
move_uploaded_file($file_array['tmp_name'], "$file_dir/".$file_array['name']) or die ("Your image couldnt be uploaded <br>");
$newpath = addslashes("uploaded/".$file_array['name']);
include "connect.php";
$addfile = "INSERT INTO slider (header, image, article) VALUES ('$header','$newpath', '$article')";
$result = mysql_query($addfile);
if ( $result === FALSE ) {
echo "your post could not be uploaded but we already got your image in our files ";
} else{
echo '<p style="padding: 20px;"><h1>Your post was successfully uploaded <h2></p><br><br>';
}
mysql_close();
} else "No file found";
}
?>
</div>
</div>
</body>
</html>