View Full Version : FTP video upload from form
I know your all getting sick of my FTP questions. . . I'm sick of askin' 'em. But my script isn't working. . . It creates the file, but puts no information in it (file size is always 0 bytes). Any help would be great.
if ($_POST['Submit'] == 'Submit'){
$conn_id = ftp_connect("localhost") or die("Couldn't connect");
$login_result = ftp_login($conn_id, "????", "??????") or die("ERROR IN FTP CONNECTION");
@ftp_mkdir($conn_id, './Information/Uploads/');
$path2 = './Uploads/';
$path = './Information/Uploads/';
$o_name = basename($_FILES['uploadedfile']['name']);
$path .= $o_name;
$path2 .= $o_name;
$temp = tmpfile();
if(ftp_fput($conn_id, $path, $temp, FTP_ASCII)){
print '<h1>File "'.$o_name.'" has been uploaded.</h1><h2>We thank you for your donation to this website, and look forward to seeing it accessed by our users.</h2>';
$path_parts = pathinfo($path);
$title = $_POST['title'];
$filetype = $path_parts['extension'];
$style = $_POST['style'];
$disc = $_POST['discription'];
$sugrank = $_POST['suggestedrank'];
$provider = $_SESSION['username'];
$notes = $_POST['notes'];
$copyright = $_POST['copyright'];
MySQL_Query("INSERT INTO files VALUES(
NULL,
'$path2',
'$title',
'$filetype',
'$style',
'$disc',
'$sugrank',
'$provider',
'$notes',
'$copyright'
)");
} else {
print "Error Uploading File:<br>$o_name";
}
MySQL_Close($Connection);
ftp_close($conn_id);
}
Or I will take an alternate script if that is easier for you guys. . . Either way. . .
tech_support
09-22-2007, 10:11 AM
I don't see any function to put in the file contents.
littleEd
09-22-2007, 12:59 PM
After quickly scanning your code I decided to see wat php.net says about using "ftp_fput"
here is the link to that page
http://www.php.net/manual/ro/function.ftp-fput.php
there is an example on it:
<?php
// open some file for reading
$file = 'somefile.txt';
$fp = fopen($file, 'r');
// set up basic connection
$conn_id = ftp_connect($ftp_server);
// login with username and password
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
// try to upload $file
if (ftp_fput($conn_id, $file, $fp, FTP_ASCII)) {
echo "Successfully uploaded $file\n";
} else {
echo "There was a problem while uploading $file\n";
}
// close the connection and the file handler
ftp_close($conn_id);
fclose($fp);
?>
the main difference i see here is that the code above uses fopen and yours does not. you are using tmpfile which to me looks like it only makes a temporary file (which when created will be blank). So My GUESS is that instead of tmpfile() you should be using fopen on that line and opening the file you are trying to use. again, that is just a guess.
insanemonkey
09-23-2007, 10:50 PM
Try this it should work, it also gives you numbers on the side to and two save buttons and refresh just in case something goes wrongs....
<?php
$loadcontent = "YUOR FILE HERE!!!!.html";
if($save_file) {
$savecontent = stripslashes($savecontent);
$fp = @fopen($loadcontent, "w");
if ($fp) {
fwrite($fp, $savecontent);
fclose($fp);
print '<a href='.$_SERVER[PHP_SELF].'>Refresh</a>';
print "<html><head><META http-equiv=\"refresh\" content=\"0;URL=$_SERVER[PHP_SELF]\"></head><body>";
}
}
$fp = @fopen($loadcontent, "r");
$loadcontent = fread($fp, filesize($loadcontent));
$lines = explode("\n", $loadcontent);
$count = count($lines);
$loadcontent = htmlspecialchars($loadcontent);
fclose($fp);
for ($a = 1; $a < $count+1; $a++) {
$line .= "$a\n";
}
?>
<form method=post action="<?=$_SERVER[PHP_SELF]?>">
<input type="submit" name="save_file" value="Save">
<table width="100%" valign="top" border="0" cellspacing="1" cellpadding="1">
<tr>
<td width="3%" align="right" valign="top"><pre style="text-align: right; padding: 4px; overflow: auto; border: 0px groove; font-size: 12px" name="lines" cols="4" rows="<?=$count+3;?>"><?=$line;?></pre></td>
<td width="97%" align="left" valign="top"><textarea style="text-align: left; padding: 0px; overflow: auto; border: 3px groove; font-size: 12px" name="savecontent" cols="150" rows="<?=$count;?>" wrap="OFF"><?=$loadcontent?></textarea></td>
</tr>
</table>
<br>
<input type="submit" name="save_file" value="Save">
</form>
I recommend not to use php if your letting other people use this, saftey reasons.. and hacking..
???? I'm confused :(
Sorry guys, but I thought I know more about FTP-- evidently not, lol. Can I get a bit more info on what's going on with your script isanemonkey ?
insanemonkey
10-01-2007, 08:57 AM
sorry... my script is like yours but it right now only edits the information and saves it..
I am currently working on how to upload, and make a new page and edit there and now..
but as of now this is what I am using for every page that i want
i don't know if this is what you are looking for but I have it up so you can test it out...
http://www.xudas.com/test/index.html
http://www.xudas.com/test/edit.php
goto index to see before look then goto edit and write something(html only) and save then goto the index.html page and see...
but any questions let me know...
oh and your site sweet n treats its pretty good.. the layout is kinda good. but not eye catching.... but AWESOME!!!
I don't think that is what I am looking for :(
I need a way to let users upload a file to the server, such as jpg's and mpeg's and pdf's and what-not. Any ideas? Can I fix the script at the start of this thread?
I don't see any function to put in the file contents.
What do I do to insert the contents into the file?
oh and your site sweet n treats its pretty good.. the layout is kinda good. but not eye catching.... but AWESOME!!!
Thanks for the input. Any suggestions? The owners wanted it "simple," so I am at a loss (The original draft was better, but they didn't like it :(). (The other website that I am working on now--my website--is really starting to pop ;) )
insanemonkey
10-02-2007, 08:59 PM
so your looking for a script that will just upload images or what not... why didnt you say that.. you don't use fopen and script like that for uploading...
welll here is a upload script... I like this one the most since it tells the person the link of the file is at....
<?php
error_reporting(E_ALL ^ E_NOTICE); // Show all major errors.
// Check to see if the button has been pressed
if (!empty($_REQUEST['sendForm']))
{
// Assign the name to a variable
$name = $_FILES['uploaded_file']['name'];
// Assign the tmp_name to a variable
$tmp_name = $_FILES['uploaded_file']['tmp_name'];
// Assign the error to a variable
$error = $_FILES['uploaded_file']['error'];
// Assign the size to a variable
$size = $_FILES['uploaded_file']['size'];
// No trailing slash
$uploadFilesTo = 'LOCATION TO YOUR UPLOADED FILES';
// Create safe filename
$name = ereg_replace('[^A-Za-z0-9.]', '-', $name);
// Disallowed file extensions
//what files you don't want upoad... leave this alone and you should be fine but you could add more
$naughtyFileExtension = array("php", "php3", "asp", "inc", "txt", "wma", "mov", "js", "exe", "jsp", "map", "obj", " ", "", "html", "mp3", "mpu", "wav", "cur", "ani"); // Returns an array that includes the extension
$fileInfo = pathinfo($name);
// Check extension
if (!in_array($fileInfo['extension'], $naughtyFileExtension))
{
// Get filename
$name = getNonExistingFilename($uploadFilesTo, $name);
// Upload the file
if (move_uploaded_file($tmp_name, $uploadFilesTo.'/'.$name))
{
// Show success message
echo '<center><p>File uploaded to http://www.yoursite.com/'.$uploadFilesTo.'/'.$name.'</p></center>';
}
else
{
// Show failure message
echo '<center><p>File failed to upload to /'.$name.'</p></center>';
}
}
else
{
// Bad File type
echo '<center><p>The file uses an extension we don\'t allow.</p></center>';
}
}
// Functions do not need to be inline with the rest of the code
function getNonExistingFilename($uploadFilesTo, $name)
{
if (!file_exists($uploadFilesTo . '/' . $name))
return $name;
return getNonExistingFilename($uploadFilesTo, rand(100, 200) . '_' . $name);
}
?>
<table bgcolor="gray" border="1"><tr>
<tr><td>
<br>
<form action="" method="post" enctype="multipart/form-data">
<input type="file" name="uploaded_file"><br>
<input type="submit" name="sendForm" value="Upload Image">
</form>
</td></tr>
</table>
now just fool around with the script.... but you have to edit some of the things though.. any question let me know
That is well commented, but, um, it also has to be for videos. . . which would require FTP (That's not FTP, is it?).
I do thank you for the script though. There are several parts that I can use, like blocking file types and fixing the filenames (which I never thought of).
insanemonkey
10-07-2007, 07:32 PM
this script runs off your server not ftp.. you don't have to have ftp to upload images or whatever, any more questions let me know...
this script runs off your server not ftp.. you don't have to have ftp to upload images or whatever, any more questions let me know...
Videos, however, really need FTP. When I try to upload mpeg videos (or any other type for that matter), the server kills over, if you know what I mean. So, I am really looking for a FTP version right now. (Your right, though, about pics. That type of transfer is perfect for image files or text files.)
insanemonkey
10-07-2007, 08:04 PM
oh.. I see what you mean, you have to talk to your hosting company becuase they only allow uploads of up to I think 8mb or 4mb, first try uploading like a mpeg or whatever that is like 4mb and see if it works..
oh.. I see what you mean, you have to talk to your hosting company becuase they only allow uploads of up to I think 8mb or 4mb, first try uploading like a mpeg or whatever that is like 4mb and see if it works..
I will be running the server (hosting companies annoy me too much, and I should have the resources to host everything myself). The problem is that the vids are just going to be to big. The type of videos that are going to be on this site are instructional, which means they could very well be 30min long. I know that you can change the settings to allow bigger files and what-not, but at some point you just have to switch to FTP.
insanemonkey
10-07-2007, 08:12 PM
ftp is for uploading files to a server I don't know if there is a such thing as a program that does this, but..
if you have your own server and you have php installed on it, then your going to have to look on the web, and find out how you can change the settings to allow uploads from like 8mb to higher,
but, I don't really know what to do, so I hope you figure it out..
What I am really looking for is someone to correct the script at the beginning of this thread. . . It is somewhat functional, but it doesn't insert the data from the uploaded to the stored file.
EDIT: I found this script:
<?php
// get FTP access parameters
$host = $_POST['host'];
$user = $_POST['user'];
$pass = $_POST['pass'];
$destDir = $_POST['dir'];
$workDir = "/usr/local/temp"; // define this as per local system
// get temporary file name for the uploaded file
$tmpName = basename($_FILES['file']['tmp_name']);
// copy uploaded file into current directory
move_uploaded_file($_FILES['file']['tmp_name'], $workDir."/".$tmpName)
or die("Cannot move uploaded file to working directory");
// open connection
$conn = ftp_connect($host) or die ("Cannot initiate connection to
host");
// send access parameters
ftp_login($conn, $user, $pass) or die("Cannot login");
// perform file upload
$upload = ftp_put($conn, $destDir."/".$_FILES['file']['name'],
$workDir."/".$tmpName, FTP_BINARY);
// check upload status
// display message
if (!$upload) {
echo "Cannot upload";
} else {
echo "Upload complete";
}
// close the FTP stream
ftp_close($conn);
// delete local copy of uploaded file
unlink($workDir."/".$tmpName) or die("Cannot delete uploaded
file from working directory -- manual deletion recommended");
?>
But what is this:
$workDir = "/usr/local/temp"; // define this as per local system
I can't figure out what it should be.
Can anyone help here?
I am really getting tired of google-ing for this, so if you guys can help I would be INSANELY grateful:
Could someone please post an FTP video upload script (that uses an HTML form). It doesn't have to be fancy, it just has to work. I have been trying and trying for months. . . :confused: :mad: :confused: :mad: I don't mean to be so annoying on FTP, but this is the last major step in the project that I am working on (still a long way to go on my site, but nothing major after this).
Thanks guys.
No one knows what it is either, huh? :) I've been trying various paths, but can figure out what it wants. . .
djr33
10-13-2007, 10:19 PM
Don't post two threads on the same subject.
If your host does not allow large uploads, that won't change, no matter what you do after the file is uploaded.
A file field in a form means that the file is sent onto the server to a temporary directory, found by tmp_name. That's the whole idea. Then it is moved by move_uploaded_file, and you can place it where you want.
If the host doesn't allow large files, it doesn't matter if you move it, use FTP to place a second instance of itself onto the same host (a complete waste of time/work), or just delete the file-- it won't work.
If FTP really does allow larger files (and it isn't just the browsers timing out, which is common on large files), then you would need to give everyone access to your FTP account.
A few ideas for workarounds:
1. Use a second server and use an FTP upload, but that seems roundabout, and if you have the second server that does work, what's the point?
2. Use another way to upload the file, like a Java applet, which might be nice for such a large file as it could give the user more info about speed, etc., while uploading.
Thanks djr33
I will be running the server (hosting companies annoy me too much, and I should have the resources to host everything myself).
What should the directory be in the context of the script?
djr33
10-14-2007, 01:38 AM
I have no idea. You pick where you want it to go...
I have no idea. You pick where you want it to go...
Not exactly. . . Every thing I have tried doesn't work. Maybe you can give it a shot and see if you can find the magic path?
djr33
10-14-2007, 02:18 AM
"define this as per local system"
Looks like you'll need to figure out where your host puts the temporary uploaded files.
Not to sound rude, but good grief man! I am the host (said it a few times on this thread) :p Hence why I can't contact the host to find out where to put it (that would be an awkward conversation. . . lots of silence and some mumbling, likely). Again, I don't want to sound rude -- your the only one stickin' with this thread :). I will be setting up my computer as the server. Do I need to configure something, or look. . . somewhere in particular?
djr33
10-14-2007, 02:41 AM
Regardless of who owns the server, you need to find out where your host [ie the hosting setup/system/configuration] actually places the data that is uploaded.
I don't know very much about server configurations, so not sure what I can suggest.
You could try to find where an uploaded file goes, just by looking for a new file when someone uploads it.
OIC. Sorry.
Is there anyone on DD that can build the script? I like to build all of my stuff myself, but I have been searching for months and haven't found a darn thing.
I found this (http://www.laurent-laville.org/spip/article.php3?id_article=22&artsuite=2) to, if it helps anyone-- but I couldn't get it to work.
tech_support
10-14-2007, 03:06 AM
What I am really looking for is someone to correct the script at the beginning of this thread. . . It is somewhat functional, but it doesn't insert the data from the uploaded to the stored file.
EDIT: I found this script:
<?php
// get FTP access parameters
$host = $_POST['host'];
$user = $_POST['user'];
$pass = $_POST['pass'];
$destDir = $_POST['dir'];
$workDir = "/usr/local/temp"; // define this as per local system
// get temporary file name for the uploaded file
$tmpName = basename($_FILES['file']['tmp_name']);
// copy uploaded file into current directory
move_uploaded_file($_FILES['file']['tmp_name'], $workDir."/".$tmpName)
or die("Cannot move uploaded file to working directory");
// open connection
$conn = ftp_connect($host) or die ("Cannot initiate connection to
host");
// send access parameters
ftp_login($conn, $user, $pass) or die("Cannot login");
// perform file upload
$upload = ftp_put($conn, $destDir."/".$_FILES['file']['name'],
$workDir."/".$tmpName, FTP_BINARY);
// check upload status
// display message
if (!$upload) {
echo "Cannot upload";
} else {
echo "Upload complete";
}
// close the FTP stream
ftp_close($conn);
// delete local copy of uploaded file
unlink($workDir."/".$tmpName) or die("Cannot delete uploaded
file from working directory -- manual deletion recommended");
?>
But what is this:
$workDir = "/usr/local/temp"; // define this as per local system
I can't figure out what it should be.
Can anyone help here?
Try %temp% ;)
(Only works on Windows)
Thanks for the suggestion, but it didn't work.
Cannot move uploaded file to working directory
tech_support
10-14-2007, 09:22 AM
Then try the root of your web folder, or don't enter anything at all.
Tried that already. Same things (even with full path or full url). I am REALLY thinking that I am missing something fundemental here. . . But I have no idea what. Can someone perhaps try to make it work, and then let me know what happened?
djr33
10-15-2007, 02:34 AM
If it were up to me, I'd start back at the beginning and reevaluate what you want to accomplish and see if there is an easier way.
tech_support
10-15-2007, 10:26 AM
Try having a look at this (http://au2.php.net/manual/en/function.ftp-put.php).
Thanks! I finally had a bit of time to look at that.
This code is working for jpeg and exe and those sorts of things:
<?php
if(isset($_POST['submit'])){
set_time_limit(0);
$ftp_server='localhost';
$conn_id = ftp_connect($ftp_server);
$myFile = $_FILES['source_file'];
$source_file = $myFile['tmp_name'];
// login with username and password
$user="";
$passwd=""
$login_result = ftp_login($conn_id, $user, $passwd);
// check connection
if ((!$conn_id) || (!$login_result)) {
echo "FTP connection has failed!";
echo "Attempted to connect to $ftp_server for user $ftp_user_name";
die;
} else {
echo "<br>Connected to $ftp_server, for user $user<br>";
}
ftp_chdir($conn_id, "/information/");
ftp_chdir($conn_id, "uploads");
echo $_FILES['source_file']['name'];
$destination_file= $_FILES['source_file']['name'];
echo ("<br>");
print $destination_file;
echo ("<br>");
// upload the file
$upload = ftp_put($conn_id, $destination_file, $source_file, FTP_BINARY);
// check upload status
if (!$upload) {
echo "FTP upload has failed!";
} else {
echo "Uploaded $source_file to $ftp_server as $destination_file";
}
// close the FTP stream
ftp_close($conn_id);
}
?>
<!--===========================================================//-->
<html>
<body marginwidth=4 marginheight=4 topmargin=4 leftmargin=4 bgcolor=white vlink="#0000ff" link="#0000ff">
<form name="Attachments" method=POST action="upload.php" enctype="multipart/form-data">
<input type=hidden name=box value="">
<td nowrap width="1%"> <b>Image:</b></td>
<input type=file name=source_file size=20> <br>
<input type="hidden" name="MAX_FILE_SIZE" value="9999999" />
<input type=submit name=submit value=submit size=20 style="border: 1px solid #0000FF"></form>
</body>
</html>
But it won't do ANYTHING for mp3 or video files. . . My guess is that PHP finds them too large. What can I do to fix this now? (As I said, everything else seems to be working.)
Thanks for your help so far. I am SOOOOOOO close to being done with this mess.
Okay, so I googled for what seemed an eternity, fiddled with tons of ". . . Do this here and put that there and type this bit of code here. . . " *Sigh* I added php_value upload_max_filesize 160M to htaccess file. It still doesn't work with videos.
BUT!!!!
It IS working with MP3's! Soooooooooo cloooooose! Anything else that I can do to push this over the edge? I will keep fiddling, but I can't get the darn videos to upload. I am in a much better mood now though. :)
djr33
10-24-2007, 07:02 PM
Is the issue filesize or file type? If it's type, then the problem is either restricted file types on the server (unlikely) or something quite easy to fix in the script.
:)I AM SO HAPPY!!!!:)
The script WORKS!!!
I uploaded the first vid just a minuet ago.
I'll post a final draft of it later for anyone who wants to use something like it-- no one deserves to go through that trying to write a script! At any rate, where should I post it when I am done (so that people can find it)?
Thanks everyone who put up with me throughout this -- I know I annoyed everyone, but hopefully now there will be no more FTP questions (from me anyway).
And how do you all feel about the uploading of EXE files? How safe are they and how can I make them . . . safer? I want to have this capability on my site, but I am worried about some nut uploading something to destory my server/computer. (As far as I know an EXE can't execute itself, but I am not really sure about that).
EDIT: Come to think of it, how can I make sure that it is safe for the user to download it?
insanemonkey
10-27-2007, 02:44 AM
actually i think it would be bad, and you shouldn't use it, edit your mime(?) types and make it so it allows you to download them instead of on command url.. I think its possible through html and a major hacker would fool with it...
is mime right your ext??'s
Er, I have no idea what you just said lol. I got the bad idea part, but after that I am a little lost. . .
insanemonkey
10-27-2007, 02:59 AM
oops im sorry that is confuzing...
do you want users to automatically download the .exe file? if so I think you can you should make it so where it downloads the files instead of it going into the browser, im not really sure though...
eek im sorry im really confuzing person...lol
Still doesn't make much sense lol. In answer to your question: No, it won't DL automatically (that would annoy users-- or make them really mad at me). The user would choose to DL it (via a hyperlink, maybe?).
BTW-- this thread is getting really long. I am starting to think I should just start a new one.
insanemonkey
10-27-2007, 03:07 AM
sorry that is what i meant, i know i hate when things dl auto.. yeh make it hyperlink, and check to see if you can load a .exe program in a browser and see what it does, i think it might ask you to dl it..
tech_support
10-28-2007, 03:56 AM
And how do you all feel about the uploading of EXE files? How safe are they and how can I make them . . . safer? I want to have this capability on my site, but I am worried about some nut uploading something to destory my server/computer. (As far as I know an EXE can't execute itself, but I am not really sure about that).
EDIT: Come to think of it, how can I make sure that it is safe for the user to download it?
ZIP the exe file after it gets uploaded ;)
ZIP the exe file after it gets uploaded ;)
Brilliant Idea!!!
I know PHP has a function to do that, but can you give an example, perhaps?
insanemonkey
11-01-2007, 09:03 PM
hey jas could you post your script, I can't seem to get it to work what I am trying todo..
I'll try to get the script up soon (I am still working on the finer points). I still don't know exactly where to post it though. I want people to be able to find it.
How soon do you need it?
pssparkman
11-04-2007, 04:31 AM
Hey man, if you can get it working. Then I'll wait!
Hey man, if you can get it working. Then I'll wait!
Read the thread. It is working :) . I just need to fine tune it, add some extra features to make it safer. . . Right now I need to look into zipping (is that a word?) the exe files for safety. When it's done, I'll be posting it.
It's here (http://www.dynamicdrive.com/forums/showthread.php?t=26422). Thanks for all your help guys!
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.