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

Posts: 2
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, 05:18 PM Re: File Upload Rename
rogem002's Avatar
Webmaster Talker

Posts: 540
Name: Mike
Location: United Kingdom
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
__________________
Website Services
PHP Code:
if(Added_Talkupation($post) == TRUE){iHug($you);} 
rogem002 is online now
Reply With Quote
View Public Profile Visit rogem002's homepage!
 
Old 04-27-2008, 05:29 PM Re: File Upload Rename
Junior Talker

Posts: 2
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

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB 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.11425 seconds with 13 queries