Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > Beginning PHP
|
Beginning PHP Beginning-level PHP discussions. More advanced coders should post to the Pro PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning PHP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 7th, 2007, 03:14 PM
Registered User
 
Join Date: May 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Uploading files, I have a problem

This is a snippet of code from the top of my script, but not to the bottom. It is supposed to generate a unique 6 digit folder name, then move the uploaded file to it. I didn't show the first block of code that generates the number and creates the folder because it works.
Code:
// Script generates a unique 6 digit number, called $randomdir
// Then it makes the appropriate folder in ./temporary/$randomdir and CHMODs it 0777
// Where the file is going to be placed 
$target_path = "temporary/$randomdir/";

// Add the original filename to our target path.  
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']); 
$_FILES['uploadedfile']['tmp_name'];  

$target_path = "temporary/$randomdir/";

$target_path = $target_path . basename( $_FILES['uploadedfile']['name']); 

if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
    echo "The file ".  basename( $_FILES['uploadedfile']['name']). 
    " has been uploaded";
} else{
    die("There was an error uploading the file, please try again");
}
All I get returned is
Code:
Temporary folder created
There was an error uploading the file, please try again
Please can somebody help me find out why the script is causing this error. It was working previously but then it stopped working and I can't fix it on my own.
Thanks
 - Sam

 
Old May 11th, 2007, 10:18 PM
Registered User
 
Join Date: Jan 2005
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to cyber_kaley
Default

<?
// Script generates a unique 6 digit number, called $randomdir
// Then it makes the appropriate folder in ./temporary/$randomdir and CHMODs it 0777
// Where the file is going to be placed


if(isset($_POST['Submit'])) {
$target_path = "temporary/$randomdir/";

// Add the original filename to our target path.
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);
$_FILES['uploadedfile']['tmp_name'];

$target_path = "images/$randomdir/";

$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);

if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
    echo "The file ". basename( $_FILES['uploadedfile']['name']).
    " has been uploaded";
} else{
    die("There was an error uploading the file, please try again");
}

}

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body>
<form action="" method="post" enctype="multipart/form-data" name="form1" id="form1">
  <label>
  <input type="file" name="uploadedfile" />
  </label>
  <p>
    <label>
    <input type="submit" name="Submit" value="Submit" />
    </label>
  </p>
</form>
</body>
</html>

caley





Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem uploading multiple (audio-video) files suchi Pro JSP 0 May 8th, 2006 02:03 PM
Uploading Files sami PHP How-To 7 April 16th, 2004 02:29 PM
Problem with uploading files linther SQL Server ASP 3 October 22nd, 2003 08:20 PM
uploading files by c# rborsatti C# 2 September 29th, 2003 03:29 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.