Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > PHP/MySQL > Beginning PHP
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old May 7th, 2007, 03:14 PM
Registered User
 
Join Date: May 2007
Location: , , .
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

Reply With Quote
  #2 (permalink)  
Old May 11th, 2007, 10:18 PM
Registered User
 
Join Date: Jan 2005
Location: mabalacat, 1020, Philippines.
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
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 Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 04:07 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.