PDA

View Full Version : Need very simple upload script


Hawtalta
04-05-2005, 10:26 PM
Basically, I need a script that can upload to a specified directory and an interface.

I have done a lot of searching, but none ot my liking. I want it to be able to preserve the file name as well. Can anyone lead me into the right direction?

I tried a couple, but none worked to well.

Brandoe85
04-05-2005, 10:45 PM
Which ones have you tried? The one from the php manual?
http://us3.php.net/features.file-upload

Hawtalta
04-05-2005, 11:16 PM
Ah, I had seen that one before but lost the link a while back. I will give that a try and let ya know if it'll work for me. I tried a couple from hostscripts.com before but don't remember which ones exactly. I'd have to go back and look.

Hawtalta
04-07-2005, 05:25 AM
Ok here is my updated file. It seems to work fine for jpg's, but wmv's just show up as 0 kb. Any idea? how can I make the destination file go to a certain directory? I swear I tried everything. the path would be public_html/uploads if anyone knows the coding for that. Or if you know of an easier way.

<?php
//declare variables
$source_file=$_FILES['userfile']['tmp_name'];
$destination_file=$_FILES['userfile']['name'];
$ftp_server= 'ftp.hawtalta.com';

// set up basic connection
$conn_id = ftp_connect($ftp_server);
$user="username";
$passwd="pass";
$login_result = ftp_login($conn_id, $user, $passwd);

// check connection
if ((!$conn_id)) {
echo "FTP connection has failed!";
echo "Attempted to connect to $ftp_server";
exit;
} else {
echo "Connected to $ftp_server <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 as $destination_file";
}

// close the FTP stream
ftp_close($conn_id);
?>

Hawtalta
04-07-2005, 10:53 PM
Anyone have any ideas?

Len Whistler
04-07-2005, 11:08 PM
How about a php script that transfers directly into a folder without using FTP?

Leonard Whistler
www.stubby.ca

Hawtalta
04-11-2005, 04:24 AM
I tried that a while back and ****ed it up. Any suggestions?

labrap
04-12-2005, 06:03 PM
I've tried this one to upload image files for my photo album. I guess it will help in case of other file formats too. The html files contains three radio buttons with values Family, Friend and Myself. When I select the file and click upload, the image I selected stores in the directory "./upload/myself" when myselft is checked. Similar with other folders.

IMPORTANT: Create a folder "upload" in the path same as of these files:
Here are the codes, upload.html and upload.php

<!--upload.html-->
<html>
<body>
<form action="upload.php" method="post">




<p><font color=\"#000000\" size=\"2\" face=\"verdana\"><b>Select a file to upload:</b></font> <br>");

<font color="#000000" size="2" face="verdana"><b>Select category:</b><br><br>
Family<input type ="radio"name="t" value="Family" checked>
Friends <input type ="radio" name="t" value="Friends">
Myself <input type ="radio" name="t" value="Myself"> </b></font>
<br><br><br>
<input type="file" name="file" size="30"> <br> <br> <br>

<input name="submit" type="submit" value="Upload">
</font>

</form>
</body>
</html>



///here in upload.php

<?php
$file=$HTTP_POST_FILES['file'];
$file_name=$file['name'];
$file_size=$file['size'];
$file_type=$file['type'];
if($file_name != ""){
$max_file_size=1024000;// 1 Mb
if($file_size>$max_file_size){echo"cannot upload the file having size of more than 1 Mb";exit;}



if($file_type=="image/gif"||$file_type=="image/pjpeg"||$file_type=="image/bmp"){

$t=$_POST["t"]; ///////SELECTED RADIO BUTTON

$dest_dir="./upload/$t";


$dest=$dest_dir."/".$file['name'];

// UPLOAD TO TEMPORARY LOCATION
if(!is_uploaded_file($file['tmp_name'])){echo"no file uploaded"; exit;}
//MOVE FROM TEMPORARY LOCATION TO DESTINATION DIRECTORY
$r=move_uploaded_file($file['tmp_name'],$dest);
if($r==FALSE) echo"COULD NOT COPY FILE";
else{
echo"<li>Sent: \"$file_name\"";
echo"<li>Size: \"$file_size\" bytes";
echo"<li>Type: \"$file_type\"";
echo"<br><br>";

}

}
else echo "image type not supported";
}
else {die("No file specified.");}

?>

Hawtalta
04-14-2005, 01:42 PM
Cool, I will give one of these a try. I think I need to try another way beside with ftp.