Jump to content

Uploading file in incorrect dir


soycharliente

Recommended Posts

Files are being uploaded to my root directory instead of the specified folder in my code. I've tried multiple options for the upload-to folder that include:

$upload_dir = './videos/';

$upload_dir = '/videos/';

$upload_dir = 'videos/';

$upload_dir = $_SERVER['DOCUMENT_ROOT'].'/videos/';

 

if (count($err) < 1 && $_FILES['File']['error'] == 0)
{
$v_URL = uploadVideo($_SESSION['UserID'],$id,$issue,$reply,$title,$desc);
$upload_dir = './videos/';
$upload_file = basename($upload_dir.$v_URL.'.'.$extension[1]);
if (move_uploaded_file($_FILES['File']['tmp_name'], $upload_file))
{
	//chmod($upload_file, 0705); this doesn't work either, but that's another post soon 
	header('Location: /video.php?id='.$v_URL);
	exit();
}
else { $err['Posting'] = '<p class="error">Could not post video. Please try again.</p>'; }
}

 

Can anyone help me? I don't know what questions to ask.

Thanks.

Link to comment
https://forums.phpfreaks.com/topic/203169-uploading-file-in-incorrect-dir/
Share on other sites

basename

(PHP 4, PHP 5)

 

basename — Returns filename component of path

 

Description

string basename ( string $path [, string $suffix ] )

Given a string containing a path to a file, this function will return the base name of the file.

 

^^^ Why are you using basename() after you have formed your upload path? ^^^

 

 

I took out the basename() call and reinserted my $_SERVER solution. Works as expected now.

chmod() works as expected too, so that fix killed two birds with one stone.

 

if (count($err) < 1 && $_FILES['File']['error'] == 0)
{
$v_URL = uploadVideo($_SESSION['UserID'],$id,$issue,$reply,$title,$desc);
$upload_dir = $_SERVER['DOCUMENT_ROOT'].'/videos/';
$upload_file = $upload_dir.$v_URL.'.'.$extension[1];
if (move_uploaded_file($_FILES['File']['tmp_name'], $upload_file))
{
	chmod($upload_file, 0705);
	header('Location: /video.php?id='.$v_URL);
	exit();
}
else { $err['Posting'] = '<p class="error">Could not post video. Please try again.</p>'; }
}

 

Thanks.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.