PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 



Go Back   Dev Articles Community ForumsProgrammingPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old June 10th, 2012, 08:01 PM
supermeow supermeow is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2012
Posts: 2 supermeow User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 53 m 54 sec
Reputation Power: 0
Question Script won't submit files w/ special characters

My script is supposed to submit files to a folder in my linux server.
It does actually submit them, but when I try to submit files with special characters, I can't redownload them. When I view them with my file manager, they have all sorts of nasty backslashes and other special characters in the filename.
These backslashes (\) render the file useless... and you can't delete them.
For example, when I submit the file: "Beethoven's Symphony No. 9 (Scherzo).wma" it uploads it as "Beethoven\'s Symphony No. 9 (Scherzo).wma".
This happens with other special characters too.

The code for my script (submitmusic.php) is:

PHP Code:
<?php
  $allowedExtensions 
= array("wav""flv""flac""ogg""aac""mp3""wma"); 
  foreach (
$_FILES as $file) { 
    if (
$file['tmp_name'] > '') {
      if (!
in_array(end(explode("."
            
strtolower($file['name']))),
            
$allowedExtensions)) { 
       die(
$file['name']." is an invalid file type/name! These are the valid file types: .wav, .flv, .flac, .ogg, .aac, .mp3, and .wma. Additionally, you cannot use symbols in the file name."
        
'<br><br><a href="javascript:history.go(-1);">'
        
'<--- Go Back</a>'); 
      } 
    } 
  }
 function 
findexts ($file
 { 
 
$file strtolower($file) ; 
 
$exts split("[/\\.]"$file) ; 
 
$n count($exts)-1
 
$exts $exts[$n]; 
 return 
$exts;
 } 
$ran time () ;

 
//This takes the random number (or timestamp) you generated and adds a . on the end, so it is ready of the file extension to be appended.
 
$ran2 =$ran;

 
//This assigns the subdirectory you want to save into... make sure it exists!
 
$target "files/";

//This combines the directory, the random file name, and the extension $target = $target . $ran2.$ext; 
  
$target $target.$ran2.$ext

 
//This applies the function to our file  
 
$ext findexts ($_FILES['uploaded']['name']) ; 
 
$file=$ran2.$ext;

/* Add the original file to our target path.  
Result is "uploads/file.extension" */

$target $target basename$_FILES['uploadedfile']['name']); 

if(
move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target)) {
    echo 
"The music file number '".$file."' has been uploaded!".'<a href="javascript:history.go(-1);">'.'<--- Go Back</a>';
} else{
    echo 
"There was an error uploading file number '".$file."', please try again!"; echo '<br><a href="javascript:history.go(-1);">'
        
'<--- Go Back</a>';
}
?>


I want to keep all NORMAL charactes (a-zA-Z0-9.)
Don't forget the period!

Reply With Quote
  #2  
Old June 13th, 2012, 11:27 AM
juacala juacala is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2012
Posts: 5 juacala User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 55 m 42 sec
Reputation Power: 0
You might have magic_quotes turned on in your server. You can disable it in a variety of ways. If you have access to the php.ini file, that's the best way. You can also use .htaccess or you can just put something into your script to undo it.

See the link below for discussion:


http://php.net/manual/en/security.m...s.disabling.php

Last edited by juacala : June 13th, 2012 at 11:28 AM. Reason: Link was not embedded

Reply With Quote
  #3  
Old June 13th, 2012, 03:06 PM
supermeow supermeow is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2012
Posts: 2 supermeow User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 53 m 54 sec
Reputation Power: 0
It Worked!

It worked, THANK YOU!

I used these settings in my 'php.ini' file:

PHP Code:
Magic quotes

Magic quotes for incoming GET/POST/Cookie data.
magic_quotes_gpc Off

Magic quotes for runtime-generated datae.gdata from SQLfrom exec(), etc.
magic_quotes_runtime Off

; Use Sybase-style magic quotes (escape ' with '' instead of \').
magic_quotes_sybase = Off 


I put a copy of the 'php.ini' file in my folder with the script file.
Again, Thank You for your input!

Last edited by supermeow : June 13th, 2012 at 03:08 PM. Reason: I forgot to say where to put my settings

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingPHP Development > Script won't submit files w/ special characters


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.

© 2003-2018 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap