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
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? ^^^

 

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.