Jump to content

Trim whitespace from uploaded file


petenaylor

Recommended Posts

Hi all

 

I need to remove the spaces in an uploaded file. I have tried str_replace and trim etc... but it doesn't work.

 

Here is my code:

 

move_uploaded_file($_FILES['image']['tmp_name'][$i], WEB_UPLOAD."/images/galleries/g".$gid."/".$_FILES['image']['name'][$i]) or die("Error uploading image ");

 

Thanks

Pete

 

Link to comment
Share on other sites

Eventhough putting all of that information on one line will work, it is a good practice, in the beginning/intermediate stages of programming, to break it all apart into variables.  This will make it much easier for you to debug.

It doesn't hurt to space out your concatenations either...well, it may increase filesize, but I have a feeling your script isn't that big to begin with.

$filename = $_FILES['image']['tmp_name'][$i];
$dest = WEB_UPLOAD . "/images/galleries/g" . $gid . "/" . $_FILES['image']['name'][$i];
move_uploaded_file($file, $dest) or die("Error uploading image ");

 

Now it shouldn't be too difficult to figure out where to use str_replace.

Link to comment
Share on other sites

Isn't it more professional/neater code?

There is nothing neat or professional about the code below.

move_uploaded_file($_FILES['image']['tmp_name'][$i], WEB_UPLOAD."/images/galleries/g".$gid."/".$_FILES['image']['name'][$i]) or die("Error uploading image ");

Professional ... and neat... code would be readable.  The above code would be fine the way it is if you didn't want to strip the whitespace, but you do.

Even though a professional coder may look at move_up.....  and str_repl... and realize what's going on, you still have an abundance of single quotes, concatenation dots, slashes, and plenty of other things that could accidentally be deleted upon debug.

 

Zane, are you saying we should or shouldn't make everything on one line?

I'm not saying to NEVER put everything on one line.  My point is, that you came to a forum asking where to put str_replace in your own code (I assume it's your own code at least).  There's is nothing neat about having no clue where to put that function.

 

Take what I said and use your best judgement.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.