kyleldi Posted October 2, 2007 Share Posted October 2, 2007 After using the many resources found on this site, i've got my script figured out except for this one part. I'm trying to use the replace cmd to remove the spaces in the information given, convert it to underscores (just to create the folder) and then strip the underscore returning it to spaces when it's done and ready to post to the sql db. My code gives me an error when using the replace cmd at all, so i'm not sure what i'm doing wrong. Anyone have any ideas? I'm actually close to getting this together thanks to everyone here. str_replace(" ","_","$name" $mkdir("files/$name", 0755); $image_part = date("")."".$HTTP_POST_FILES['file01']['name']; $image_list[14] = $image_part; copy($HTTP_POST_FILES['file01']['tmp_name'], "files/$name/".$image_part); $image_part = date("")."".$HTTP_POST_FILES['file02']['name']; $image_list[15] = $image_part; copy($HTTP_POST_FILES['file02']['tmp_name'], "files/$name/".$image_part); $image_part = date("")."".$HTTP_POST_FILES['file03']['name']; $image_list[16] = $image_part; copy($HTTP_POST_FILES['file03']['tmp_name'], "files/$name/".$image_part); $where_form_is="http".($HTTP_SERVER_VARS["HTTPS"]=="on"?"s":"")."://".$SERVER_NAME.strrev(strstr(strrev($PHP_SELF),"/")); Quote Link to comment https://forums.phpfreaks.com/topic/71546-solved-replace-cmd/ Share on other sites More sharing options...
haaglin Posted October 2, 2007 Share Posted October 2, 2007 Try change this: str_replace(" ","_","$name" $mkdir("files/$name", 0755); to this: str_replace(" ","_",$name); mkdir("files/$name", 0755); What is the error? Quote Link to comment https://forums.phpfreaks.com/topic/71546-solved-replace-cmd/#findComment-360238 Share on other sites More sharing options...
kyleldi Posted October 2, 2007 Author Share Posted October 2, 2007 With error reporting on, it doesn't give me an error. It does execute the script, but the space is still in the dir name. Quote Link to comment https://forums.phpfreaks.com/topic/71546-solved-replace-cmd/#findComment-360243 Share on other sites More sharing options...
haaglin Posted October 2, 2007 Share Posted October 2, 2007 Sorry.. forgot something in the last code.. try this: $name = str_replace(" ","_",$name); mkdir("files/$name", 0755); Quote Link to comment https://forums.phpfreaks.com/topic/71546-solved-replace-cmd/#findComment-360244 Share on other sites More sharing options...
kyleldi Posted October 2, 2007 Author Share Posted October 2, 2007 works like a charm, is there any way I can convert it back to spaces once it's done creating the dir? It posts to a db and I was hoping to have it w/o the underscore in the end. Thanks so much for your help! Quote Link to comment https://forums.phpfreaks.com/topic/71546-solved-replace-cmd/#findComment-360246 Share on other sites More sharing options...
haaglin Posted October 2, 2007 Share Posted October 2, 2007 you can do it like this: $dirname = str_replace(" ","_",$name); mkdir("files/$dirname", 0755); Then $name is not changed.. Quote Link to comment https://forums.phpfreaks.com/topic/71546-solved-replace-cmd/#findComment-360249 Share on other sites More sharing options...
kyleldi Posted October 2, 2007 Author Share Posted October 2, 2007 Everything works great, the only thing I have a problem with is that if the customer name (and its dir) already exists, it outputs an error instead of appending.. shouldn't it just append? It did actually finish the script, though. It just output an error. Quote Link to comment https://forums.phpfreaks.com/topic/71546-solved-replace-cmd/#findComment-360254 Share on other sites More sharing options...
haaglin Posted October 2, 2007 Share Posted October 2, 2007 Yeah.. you need to check if the folder exists before creating it.. $dirname = "files/".str_replace(" ","_",$name); if(!file_exists($dirname")) mkdir($dirname, 0755); Quote Link to comment https://forums.phpfreaks.com/topic/71546-solved-replace-cmd/#findComment-360255 Share on other sites More sharing options...
kyleldi Posted October 2, 2007 Author Share Posted October 2, 2007 It reports an error, Parse error: syntax error, unexpected '"' in submitquote.php on line 51 <- the line of the if statement your code looks correct, so i'm not sure what's mistaken Quote Link to comment https://forums.phpfreaks.com/topic/71546-solved-replace-cmd/#findComment-360258 Share on other sites More sharing options...
haaglin Posted October 2, 2007 Share Posted October 2, 2007 Sorry.. forgot to remove a qoute.. this should work: $dirname = "files/".str_replace(" ","_",$name); if(!file_exists($dirname)) mkdir($dirname, 0755); Quote Link to comment https://forums.phpfreaks.com/topic/71546-solved-replace-cmd/#findComment-360259 Share on other sites More sharing options...
roopurt18 Posted October 2, 2007 Share Posted October 2, 2007 If you look carefully you will see an extra double quote in this line: if(!file_exists($dirname")) mkdir($dirname, 0755); Quote Link to comment https://forums.phpfreaks.com/topic/71546-solved-replace-cmd/#findComment-360260 Share on other sites More sharing options...
kyleldi Posted October 2, 2007 Author Share Posted October 2, 2007 thank you very much for your help! Quote Link to comment https://forums.phpfreaks.com/topic/71546-solved-replace-cmd/#findComment-360265 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.