Upload script problems - REP THOSE THAT FIX!

J03

~~~~~~~~
Messages
5,558
Location
Wales
OK - I have been helping j.venning with his Upload Script, and have come into a problem. This code:


PHP:
<?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:
[b]Warning[/b]:  move_uploaded_file(4969upload/IMG11.jpgIMG11.jpg): failed to open stream: No such file or directory in [b]/hsphere/local/home/cvenning/vee-media.com/php.php[/b] on line [b]11[/b]

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

[b]Warning[/b]: Cannot modify header information - headers already sent by (output started at /hsphere/local/home/cvenning/vee-media.com/php.php:11) in [b]/hsphere/local/home/cvenning/vee-media.com/php.php[/b] on line [b]25[/b]

Error. As the title says, REP TO THOSE THAT HELP :D
 
Re: Upload script problems - REP THOSE THAT FIX! FIXED!!!!!

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

PHP:
<?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!
 
Back
Top Bottom