Reply
Old 04-27-2008, 05:29 PM File Upload Rename
Junior Talker

Posts: 2
Trades: 0
I've got a file that is not functioning quite right, and I'm having trouble seeing what I did wrong.

Essentially what's happening, is when you go to upload a file such as "image.jpg", it's being renamed as "image-jpg", which essentially makes it useless.

This is the code as of right now.

Code:
 foreach ($_FILES["image"]["error"] as $key => $error) 
 {
    if ($error == UPLOAD_ERR_OK) 
  {
     $tmp_name = $_FILES["image"]["tmp_name"][$key];
     $name = $_FILES["image"]["name"][$key];
     $name = preg_replace("/([^a-z0-9])+/i", "-", $name);    
     move_uploaded_file($tmp_name, "../photo/$name");
     chmod("../photo/$name", 0777);
     echo "Image Uploaded";
     $IMAGE[] = $name;
  }
 
 }
DoubleR-Rob is offline
Reply With Quote
View Public Profile
 
 
When You Register, These Ads Go Away!
Old 04-27-2008, 06:18 PM Re: File Upload Rename
rogem002's Avatar
Super Spam Talker

Latest Blog Post:
Making Zebra Stripes with CSS3
Posts: 835
Name: Mike
Location: United Kingdom
Trades: 0
Give the following a go:

PHP Code:
 foreach ($_FILES["image"]["error"] as $key => $error
 {
    if (
$error == UPLOAD_ERR_OK
  {
     
$tmp_name $_FILES["image"]["tmp_name"][$key];
     
$name $_FILES["image"]["name"][$key];
     
#$name = preg_replace("/([^a-z0-9])+/i", "-", $name);    
     
move_uploaded_file($tmp_name"../photo/$name");
     
chmod("../photo/$name"0777);
     echo 
"Image Uploaded";
     
$IMAGE[] = $name;
  }
 
 } 
Looks to me like the preg was being naughty
__________________
PHP Code:
Add_Talkupation('rogem002'); // Because sharing is awesome! 
Fix 90% of your problems | Full On Design
rogem002 is offline
Reply With Quote
View Public Profile Visit rogem002's homepage!
 
Old 04-27-2008, 06:29 PM Re: File Upload Rename
Junior Talker

Posts: 2
Trades: 0
I never thought of doing that...lol
DoubleR-Rob is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to File Upload Rename
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 



Page generated in 0.21936 seconds with 13 queries