PDA

View Full Version : uploading files to server


image
09-16-2002, 08:08 AM
I'm looking for a way to have the ability for a website visiter to upload graphic files (gif, jpg) to the server from within a table.

The table will also include other information pertaining to each graphic uploaded that I would need emailed to me or placed on the server in a way that I can retrieve.

The following is a Non-Working Example ... example here (http://www.imagexposure.com/update.htm)

Is there anything like FormMail that allows for uploading graphics to the server ?

BoR|S
09-16-2002, 09:13 AM
You can write a small ASP or PHP code to do the job...

image
09-16-2002, 05:57 PM
Originally posted by BoR|S
You can write a small ASP or PHP code to do the job...

Thanks, I don't know anything about ASP or PHP. I'll look into it and see if I can learn how to write the code

BoR|S
09-16-2002, 08:23 PM
I'll post the source in ASP in the evening when I'm back from school...
Make sure your host supports ASP thought...

image
09-19-2002, 06:22 AM
Originally posted by BoR|S
I'll post the source in ASP in the evening when I'm back from school...
Make sure your host supports ASP thought...


My host supports PHP v4 not ASP

BoR|S
09-19-2002, 09:56 AM
Hmmm... okey... I'll try to find a PHP code for it... (I still learn PHP)...

BTW, about the ASP code I told I will upload, sorry, I just lost one of my backup CDs (probobly at my friend's house, so I'll have to pay him a visit and take it)

Sky
09-27-2002, 12:10 PM
Ok. I took your suggestion, and it works for uploading. is there a way I can change it to put it into a certian folder depending on what the uploader selects (dropdown, radio, etc) and then can it be modified to 'browse' those files and download them? this is the site i'm using them it on- www.flash.slickshosting.com/mr/mr_europroj.html and the page- www.flash.slickshosting.com/mr/mr_vehicswap.php if that give you better insight as to what im doing. Thanks :D

--sky

Sky
09-28-2002, 05:02 PM
Ok, different idea. how about it just has a (side?) script that can read the contents of a 'said' directory and display each file (except any defined?) as a link able to be downloaded? or even view all the contents of the 'said' directory and it's underlings(subdirs) as a tree with links as said above? I'd like to get this integrated into the site but I guess if that's to hard i can just use my forums...

Sky
09-29-2002, 10:29 AM
Ok.. I just got a php script that can view files/dirs from below a said dir. but i need it to display the files as links! :p
Wonder how i could do that.... I'm going to start learning php now.. :D btw where's the script and just check my page (http://www.flash.slickshosting.com/mr/rovers/test.php) for the current situation. (i'm experimenting with a require page, for getting the parts, like header body footer etc...)

your(thanks alot!! :D) script with my modifications...
form enctype="multipart/form-data" action="<?php echo $_SERVER["PHP_SELF"]; ?>" method="post">
<b>What kind of zip are you giving me? A...</b><input type="hidden" name="MAX_FILE_SIZE" value="2048000" />
<select name="folder">
<option>general_rover/
<option>contest_rover/
<option>skin/
</select><br />
<b>The file is...</b> <input name="userfile" type="file" /><br />
<input type="submit" value="Upload the zip!" />
</form>

<?php
if (@is_uploaded_file($_FILES["userfile"]["tmp_name"])) {
copy($_FILES["userfile"]["tmp_name"], $_POST["folder"] . $_FILES["userfile"]["name"]);
echo "<p><i><b><font size="3" color="#33cc33">Zip uploaded</font></b></i></p>";
}
?>

the view script
<?php
$basedir = "/home/virtual/site5/fst/var/www/html/mr/rovers/"; // Base directory

function listall($dir)
{
// Initialize temporary arrays for sorting
$dir_files = $dir_subdirs = array();

// Print current directory
print( "<ul>");
print( "<li><b>$dir</b>\n");

// Change to directory
chdir($dir);

// Open directory;
$handle = @opendir($dir) or die( "Directory \"$dir\"not found.");

// Loop through all directory entries, construct
// two temporary arrays containing files and sub directories
while($entry = readdir($handle))
{
if(is_dir($entry) && $entry != ".." && $entry != ".")
{
$dir_subdirs[] = $entry;
}
elseif($entry != ".." && $entry != ".")
{
$dir_files[] = $entry;
}
}

// Sort files and sub directories
sort($dir_files);
sort($dir_subdirs);

// Print all files in the curent directory
for($i=0; $i<count($dir_files); $i++)
{
print( "<li>$dir_files[$i]\n");
}

// Traverse sub directories
for($i=0; $i<count($dir_subdirs); $i++)
{
listall( "$dir$dir_subdirs[$i]/");
}
print( "</ul>");

// Close directory
closedir($handle);
}

listall($basedir);
?>

Sky
09-29-2002, 11:22 AM
Well, right now i could give less about validating. but i'm sure i will sometime soon. and i didn't change anything in the view script, so that's not directly my fault :D anyhoo thanks me try that.

Sky
09-29-2002, 11:57 AM
WTF?!!? i'm getting this... "Parse error: parse error, unexpected T_LNUMBER, expecting ',' or ';' in /home/virtual/site5/fst/var/www/html/mr/upload.php on line 15"
for this...

<form enctype="multipart/form-data" action="<?php echo $_SERVER["PHP_SELF"]; ?>" method="post">
<b>What kind of zip are you giving me? A...</b><input type="hidden" name="MAX_FILE_SIZE" value="2048000" />
<select name="folder">
<option>general_rover/
<option>contest_rover/
<option>skin/
</select><br />
<b>The file is...</b> <input name="userfile" type="file" /><br />
<input type="submit" value="Upload the zip!" />
</form>

<?
if (@is_uploaded_file($_FILES["userfile"]["tmp_name"])) {
copy($_FILES["userfile"]["tmp_name"], $_POST["folder"] . $_FILES["userfile"]["name"]);
LN15--> echo "<p><i><b><font size="3" color="#33cc33">Zip uploaded</font></b></i></p>";
}
?>

Sky
09-29-2002, 03:19 PM
now i get this Parse error: parse error, unexpected T_CONSTANT_ENCAPSED_STRING in /home/virtual/site5/fst/var/www/html/mr/upload.php on line 15

Sky
09-29-2002, 07:00 PM
OK. i'll try it. maybe ie wouldn't really re-load it, i don't know. I'll make it work. I know i can.

pezland
09-30-2002, 10:14 PM
*gasp*

Never ever, ever ever, never leave a browsable directory structure in your site (such as by leaving out the index.html/index.php file), if its at all possible to avoid. Very insecure, especially with server scripts like PHP. The PHP script you found to generate these structures and links is a much safer alternative.

Sky
10-01-2002, 07:11 AM
Err so you are criticising or praising my choice? :smack:

pezland
10-01-2002, 10:21 AM
LOL, praise... sorry ;)

phillyph
03-02-2003, 08:57 AM
Originally posted by dbindel
Here's some simple PHP uploader code I wrote. This put the uploaded file in a directory called "files" (relative to the directory location of where the following code is).


<form enctype="multipart/form-data" action="<?php echo $_SERVER["PHP_SELF"]; ?>" method="post">
<input type="hidden" name="MAX_FILE_SIZE" value="2048000">
File: <input name="userfile" type="file" /><br />
<input type="submit" value="Upload" />
</form>

<?php
if (@is_uploaded_file($_FILES["userfile"]["tmp_name"])) {
copy($_FILES["userfile"]["tmp_name"], "files/" . $_FILES["userfile"]["name"]);
echo "<p>File uploaded successfully.</p>";
}
?>


If you need some more help fixing this code to your project's specifications, ask.

HTH,
David Bindel


so if i just create a folder called files in the forums main dir. and upload this script (like it is), it will work?

James Robinson
06-05-2003, 11:47 AM
I need to be able to send large files to the server... up to say 25Mg.

The browser seems to time out "The page cannot be displayed".

Any Ideas?

Here is the code.
------------------------------
<?php ini_set('upload_max_filesize','20000000'); ?>
<html>
<head>
<body>
<form enctype="multipart/form-data" action="<?php echo $_SERVER["PHP_SELF"]; ?>" method="post">
<input type="hidden" name="MAX_FILE_SIZE" value="2048000">
File: <input name="userfile" type="file" /><br />
<input type="submit" value="Upload" />
</form>

<?php
if (@is_uploaded_file($_FILES["userfile"]["tmp_name"])) {
copy($_FILES["userfile"]["tmp_name"], "files/" . $_FILES["userfile"]["name"]);
echo "<p>File uploaded successfully.</p>";
}
?>
</body></html>

----------------------------
Thanks!
James

James Robinson
06-05-2003, 11:49 AM
Sorry, I know I put 20Mg as the max, but it did not work for my test file of 4.7Mg.

James

James Robinson
06-06-2003, 11:41 AM
Nope...Still did not work. Here is the entire code. It pops up "Not uploaded" at the beginning, however, if the file is uploaded, that line changes... as opposed to it saying nothing.
----------------------
<?php ini_set('upload_max_filesize','20M'); ?>
<html>
<head>
<body>
<form enctype="multipart/form-data" action="<?php echo $_SERVER["PHP_SELF"]; ?>" method="post">
<input type="hidden" name="MAX_FILE_SIZE" value="20000000">
File: <input name="userfile" type="file" /><br />
<input type="submit" value="Upload" />
</form>

<?php
if (@is_uploaded_file($_FILES["userfile"]["tmp_name"])) {
copy($_FILES["userfile"]["tmp_name"], "files/" . $_FILES["userfile"]["name"]);
echo "<p>File uploaded successfully.</p>";
}else{echo "Not uploaded<br>";
}
?>
</body></html>

-----------------------------
Thanks,
James

James Robinson
06-06-2003, 11:14 PM
the server (web host) has control of the php.ini file... I guess I should have realized that you hold your own site... therefore you could change it... Im also going to wait to hear back from them... but I thought ini_set would override it.... hummm.. :(

James Robinson
06-07-2003, 12:10 AM
Thanks!

.htaccess worked great!

<ifModule mod_php4.c>
php_value upload_max_filesize 25M
php_value max_execution_time "0"
</IfModule>

...was the modification...

Thanks again!

James

p.s. Who's the chap in the suit on one of your developed pages in your portfollio? Looks familiar! :)

James Robinson
06-07-2003, 08:28 PM
Now I have run into the next hurdle... the 8Mg limit, memory, processing time... not quite sure!

ErrorDocument 404 /index.html
<ifModule mod_php4.c>
php_value post_max_size 55M
php_value upload_max_filesize 50M
php_value memory_limit 55M
php_value max_execution_time "0"
</IfModule>

I think I have covered all my basis here... but... still nothing... Any more ideas?

I get the message "The page cannot be displayed", however, it comes EXACTLY 30 seconds after I hit upload!

Guess I counted my eggs before they hatched!

James

James Robinson
06-07-2003, 08:59 PM
php_value max_input_time "0"

I am going to assume that when all these values are set to "0" that means no time limit, however to be sure, I also tried setting them all to 3600 (60mins).

No change.... Im finding it hard to understand that if I upload a file that is 7.8Mg... it will take some time to upload... (15mins or whatever... never sat around to watch).. however, as soon as I go to 8.3Mg, EXACTLY 30 SECONDS (Ive been clock watching) after I hit submit it times out.... why 30 seconds?

I am bewildered!

jigal
06-10-2003, 03:15 AM
Originally posted by dbindel
I googled and the most popular solution to fixing a 30 second time limit is putting this line at the beginning of your script:
<?php set_time_limit(0); ?>


You can use set_time_limit() anywhere in you're code. In most cases the problem of the time limit arises in scripts that repeat the same kind of action a lot of times. In those cases it's better to put the set_time_limit() call inside the loop and set a reasonable time limit for one cycle of the loop.

Setting the time limit to 0 (=no limit) can cause a script to run forever. Most hosting companies are "not amused" when you let a script run like that...

Jigal.

James Robinson
06-11-2003, 01:16 AM
Still not working... :(

----------------------
php file:
<?php
ini_set('upload_max_filesize','50M');
ini_set('post_max_size','55M');
ini_set('max_execution_time','3600');
ini_set('memory_limit','50M');
ini_set('max_input_time','3600');
set_time_limit(3600);
.....
---------------------
.htaccess:
<ifModule mod_php4.c>
php_value post_max_size 55M
php_value upload_max_filesize 50M
php_value max_execution_time "3600"
php_value memory_limit 55M
php_value max_input_time "3600"
</IfModule>
---------------------
I think Ive tried it all... Now keep in mind...

it takes about 5-15 mins to download a 7.8Mg file... successfully... which is good...

but as soon as I go over the 8Mg limit, it gives me:
The page cannot be displayed
.
.
.
Cannot find server or DNS Error
Internet Explorer

...and this is when it times out in EXACLY 30 seconds.

Does anyone know if there are settings in my browser that will not allow that to happen?

Any other ideas?
:eek:

dogensan
09-11-2007, 07:01 PM
Thanks for the script guys - works a treat.

Does anyone know how I'd go about modifying the above code in order to replace spaces with underscores?

ie. if I upload a file: this is an image.jpg
it would be great if that were converted to this_is_an_image.jpg

Thanks in advance.

bharanikumarphp
03-27-2008, 02:22 AM
friends how to upload the more then 10 mb

with touching the php.ini file
becoz my server in remote place

any idea..

Terminator1138
03-28-2008, 08:00 PM
friends how to upload the more then 10 mb

with touching the php.ini file
becoz my server in remote place

any idea..
check with your host first to see if they will change this for you.