Go Back   Computer Forums > Web Design | Website Development > Web Programming
Click Here to Login
Join Computer forums Today


Reply
 
Thread Tools Search this Thread Display Modes
 
Old 12-28-2006, 06:43 PM   #1
j03
~~~~~~~~
 
Join Date: Jan 2005
Location: Wales
Posts: 5,556
Send a message via MSN to j03
Default Upload script problems - REP THOSE THAT FIX!

OK - I have been helping j.venning with his Upload Script, and have come into a problem. This code:


PHP Code:
<?php
session_start
();
$target "upload/";
$target $target basename$_FILES['uploaded']['name']) ;
$ok=100;
$target str_replace(php,phps,$target);
$target $target basename$_FILES['uploaded']['name']) ;
$random_digit=rand(0000,9999);
$target $random_digit.$target;
if(
move_uploaded_file($_FILES['uploaded']['tmp_name'], $target))
{
if (
$uploaded_size 3500000)
{
echo 
"Your file is too large.<br>";
$ok=0;
}
$_SESSION['filename'] = "http://vee-media.com/$target";
$URL="http://www.vee-media.com/uploaded.php";
header ("Location: $URL");
}
else
{
$URL="http://www.vee-media.com/not_uploaded.html";
header ("Location: $URL");
}
?>
Gives us this:

Code:
Warning:  move_uploaded_file(4969upload/IMG11.jpgIMG11.jpg): failed to open stream: No such file or directory in /hsphere/local/home/cvenning/vee-media.com/php.php on line 11

Warning:  move_uploaded_file(): Unable to move '/tmp/phpABi6hx' to '4969upload/IMG11.jpgIMG11.jpg' in /hsphere/local/home/cvenning/vee-media.com/php.php on line 11

Warning: Cannot modify header information - headers already sent by (output started at /hsphere/local/home/cvenning/vee-media.com/php.php:11) in /hsphere/local/home/cvenning/vee-media.com/php.php on line 25
Error. As the title says, REP TO THOSE THAT HELP
__________________

j03 is offline   Reply With Quote
Old 12-28-2006, 08:39 PM   #2
In Runtime
 
j.venning's Avatar
 
Join Date: Mar 2006
Posts: 220
Send a message via ICQ to j.venning Send a message via MSN to j.venning
Default Re: Upload script problems - REP THOSE THAT FIX! FIXED!!!!!

Myself and Samurai have fixed the PHP script now. It is as follows:

PHP Code:
<?php
session_start
();
$target basename$_FILES['uploaded']['name']) ;
$ok=100;
$target str_replace(php,phps,$target);
$random_digit=rand(0000,9999);
$target $random_digit.$target;
if(
move_uploaded_file($_FILES['uploaded']['tmp_name'], $target))
{
if (
$uploaded_size 3500000)
{
echo 
"Your file is too large.<br>";
$ok=0;
}
$_SESSION['filename'] = "http://vee-media.com/upload/$target";
$URL="http://www.vee-media.com/uploaded.php";
header ("Location: $URL");
}
else
{
$URL="http://www.vee-media.com/not_uploaded.html";
header ("Location: $URL");
}
?>
The above PHP will upload the file to the /upload/ folder but will also add a random four digit number to the begining of the file so for example it would be:

http://www.vee-media.com/upload/1234yourfile.yourfile

There is also a safeguard with uploading php files, the filename will change if a file is uploaded so it cant execute. E.g file.php will change to file.phps

Thank you very much Joe!
__________________
Brand new setup!

Intel Core 2 Quad Extreme Edition QX6800 (2.93GHz)
Intel Extreme D975XBX2KR Motherboard
BFG GeForce 8800 GTX 768MB GDDR3
Corsair 2GB DDR2 XMS2 Dominator RAM
Thermaltake VE2000SWA Armour LCS Super Tower
Western Digital Raptor X 150GB X2
j.venning is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off



All times are GMT -5. The time now is 09:41 PM.


Powered by vBulletin® Version 3.8.8 Beta 4
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Search Engine Friendly URLs by vBSEO 3.6.0